Hi Everyone,
Can Anyone explain to me where I am going wrong, I am having some great difficulty with a query named "qry_Query1" that gets recreated using the below code.
I have a form with a combox that selects a value then actions on the event with the below code to filter records based on the value the users selects, sounds simple enough, but instead of getting any results I end up creating a parameter query as below:
Anyone that can throw some light on my VBA Sql errors I would be most grateful.
The VBA code I have so far is as follows"
Code:
Private Sub Command7_Click()
Dim db As DAO.Database
Dim qd As QueryDef
Dim vWhere As Variant
Stop
Set db = CurrentDb()
On Error Resume Next
db.QueryDefs.Delete "qry_Query1"
On Error GoTo 0
vWhere = Null
'Apptsurname = field
vWhere = vWhere & " AND ApptSurname=" + Me.cboPayeeID '''selected combobox value
Set qd = db.CreateQueryDef("qry_Query1", "SELECT * FROM tblAppointments WHERE " & _
Mid(vWhere, 6))
db.Close
Set db = Nothing
Stop
DoCmd.OpenQuery "qry_Query1", acViewNormal, acReadOnly
End If
End Sub
This is the sql of qry_Query1
Code:
SELECT *
FROM tblAppointments
WHERE (((tblAppointments.[ApptSurname])=[Smith]));
Below is what I would like to achieve but without any success for "qry_Query1"
Code:
SELECT *
FROM tblAppointments
WHERE (((tblAppointments.[ApptSurname])="Smith"));