gheyman
Well-known Member
- Joined
- Nov 14, 2005
- Messages
- 2,347
- Office Version
- 365
- Platform
- Windows
This is all new to me. I am reading posts and trying to piece together how you change the Sql code of a query using VBA. Here is what I did - but it does not work. In my code the Line that starts with WHERE (((.... turned Red. When I try to run it, I get a message that reads: Compile Error: Sub or Function not defined.
any help is appreciated
Ultimately what I would like to do is an If statement that switches the SQL from one to another
Code:
Private Sub createQry()
Dim db As DAO.Database
Set db = CurrentDb
Dim qdf As DAO.QueryDef
Dim newSQL As String
newSQL = "SELECT tbl_NIS_TSL.ID_NISTSL, tbl_NIS_TSL.VendorName, tbl_NIS_TSL.VendorID, tbl_NIS_TSL.CityName, tbl_NIS_TSL.MailState, tbl_NIS_TSL.PostalCode, tbl_NIS_TSL.CountryCode, tbl_NIS_TSL.Vendor_Status, tbl_NIS_TSL.CommType, tbl_NIS_TSL.Debarred, tbl_NIS_TSL.Approval_Status, tbl_NIS_TSL.TSL_Trend, tbl_NIS_TSL.Complexity_Low, tbl_NIS_TSL.Complexity_Medium, tbl_NIS_TSL.Complexity_High, tbl_NIS_TSL.Volume_Low, tbl_NIS_TSL.Volume_Medium, tbl_NIS_TSL.Volume_High, tbl_NIS_TSL.Responsiveness_Rating, tbl_NIS_TSL.RTV_Support, tbl_NIS_TSL.Failure_Analysis, tbl_NIS_TSL.Other_Capabilities, tbl_NIS_TSL.NumberOf_Assemblies, tbl_NIS_TSL.Materials, tbl_NIS_TSL.Restrictions, tbl_NIS_TSL.Comments, tbl_NIS_TSL.CreatedBy, tbl_NIS_TSL.CreatedDate"
FROM tbl_NIS_TSL
WHERE (((tbl_NIS_TSL.VendorName) Like [Forms]![frm_NIS_TSL]![Combo227]) And ((tbl_NIS_TSL.CommType) Like [Forms]![frm_NIS_TSL]![Combo232]) And ((tbl_NIS_TSL.Debarred) Like [Forms]![frm_NIS_TSL]![Combo229]) And ((tbl_NIS_TSL.Approval_Status) Like [Forms]![frm_NIS_TSL]![Combo234]))ORDER BY tbl_NIS_TSL.VendorName, tbl_NIS_TSL.CreatedDate DESC;"
Set qdf = db.CreateQueryDef("qry_Temp", newSQL)
End Sub
any help is appreciated
Ultimately what I would like to do is an If statement that switches the SQL from one to another