I have VBA to run a query that connects to a form with a date range. I'm trying to write an IF statement that incorporates two text boxes for Start Date and End Date. I'm getting a syntax error on my below IF statement can you help? :
Option Compare Database
Function ImportPurchases()
Dim qdfPassThrough As DAO.QueryDef
Dim MyDB As Database
Dim strConnect As String
Set db = CurrentDb()
DoCmd.SetWarnings False
Set qdfPassThrough = db.QueryDefs("Netezza_abc_purch_track")
If Not IsNull((Forms![DateRange].StartDate)) And Not IsNull((Forms![DateRange].EndDate)) Then
strSQL = "SELECT A.STORE_NBR,A.ITEM_NBR, A.NDC_NBR, C.BUSINESS_UNIT_NBR, C.INV_CUST_NAME ,C.BUSINESS_UNIT_NAME, Sum(SHIPPED_QTY)as Allocated_Qty, Sum(INV_LINE_AMT) as Extended_Cost FROM FCT_DLY_INVOICE_DETAIL A, FCT_DLY_INVOICE_HEADER B, DIM_INVOICE_CUSTOMER C WHERE A.INV_HDR_SK = B.INV_HDR_SK AND B.DIM_INV_CUST_SK = C.DIM_INV_CUST_SK AND A.STORE_NBR=B.STORE_NBR AND A.INV_DT BETWEEN (" & Forms![DateRange].StartDate & ")and (" & Forms![DateRange].EndDate & ")AND A.SUPPLIER_NBR NOT IN ('50000181', '20000775', '50000809', '50000950') AND A.SRC_SYS_CD = 'ABC' AND C.INV_CUST_NAME NOT LIKE '%340B%' AND C.BUSINESS_UNIT_NAME NOT LIKE '%340B%' Group by 1,2,3,4,5,6"
Else
strSQL = "ERROR"
End If
qdfPassThrough.SQL = strSQL
strConnect = "ODBC;DSN=NZSQL;Database=PRD_EDW_RXPURCHASING_DB;Server"
qdfPassThrough.Connect = strConnect
qdfPassThrough.Close
DoCmd.SetWarnings True
End Function
db? I only seeMyDB. - MoondogsMaDawgOption Explicit. - Smandoli