Frankie_The_Flyer
Registered User.
- Local time
- Tomorrow, 10:19
- Joined
- Aug 16, 2013
- Messages
- 39
Hi Accessers!
Another little thing that is driving me insane and that I can't find an answer to on the forum or through Google!
I have a process that lifts a highlighted date from a List Box and puts it in the Criteria of a query. The process manages to move the numbers from one place to another, but ends up giving me a data mismatch in the query.
The process is as follows
Private Sub Command8_Click()
'Set it all up for Panel Meeting selection
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim varItem As Variant
Dim strCriteria As String
Dim strSQL As String
'Identify Query
Set db = CurrentDb()
Set qdf = db.QueryDefs("Qry_Panel_Dates")
'Find selected data in Listbox
For Each varItem In Me!Dates_List.ItemsSelected
strCriteria = strCriteria & " '" & Me!Dates_List.ItemData(varItem) & "' "
Next varItem
' select all if no selection has been made
If Len(strCriteria) = 0 Then
MsgBox "You did not select anything from the list" _
, vbExclamation, "Nothing to find!"
Exit Sub
End If
'Prepare String for query
strSQL = "SELECT * FROM tbl_Panel_Meeting_Dates " & "WHERE tbl_Panel_Meeting_Dates.PanelDates IN (" & strCriteria & ");"
' put it in the Query
Debug.Print strSQL
qdf.SQL = strSQL
qdf.Close
'Open the query to view
DoCmd.Close
DoCmd.OpenQuery "Qry_Panel_Meeting_Date_List_Selected"
' Finish Macro
Set db = Nothing
Set qdf = Nothing
End Sub
(NOTE the DoCmd.OpenQuery is highlighted in Yellow)
strCriteria (which comes up as I hover over the IN bit of the WHERE) shows strCriteria= " '1/07/2013' " which is the correct date selected.
The Immideate debug shows...
SELECT * FROM tbl_Panel_Meeting_Dates WHERE tbl_Panel_Meeting_Dates.PanelDates IN ( '1/07/2013' );
I'm pretty sure (althiough always stand to be corrected!) that I need it to come out as
In (#1/07/2013#)
How can this be achieved please??
Another little thing that is driving me insane and that I can't find an answer to on the forum or through Google!
I have a process that lifts a highlighted date from a List Box and puts it in the Criteria of a query. The process manages to move the numbers from one place to another, but ends up giving me a data mismatch in the query.
The process is as follows
Private Sub Command8_Click()
'Set it all up for Panel Meeting selection
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim varItem As Variant
Dim strCriteria As String
Dim strSQL As String
'Identify Query
Set db = CurrentDb()
Set qdf = db.QueryDefs("Qry_Panel_Dates")
'Find selected data in Listbox
For Each varItem In Me!Dates_List.ItemsSelected
strCriteria = strCriteria & " '" & Me!Dates_List.ItemData(varItem) & "' "
Next varItem
' select all if no selection has been made
If Len(strCriteria) = 0 Then
MsgBox "You did not select anything from the list" _
, vbExclamation, "Nothing to find!"
Exit Sub
End If
'Prepare String for query
strSQL = "SELECT * FROM tbl_Panel_Meeting_Dates " & "WHERE tbl_Panel_Meeting_Dates.PanelDates IN (" & strCriteria & ");"
' put it in the Query
Debug.Print strSQL
qdf.SQL = strSQL
qdf.Close
'Open the query to view
DoCmd.Close
DoCmd.OpenQuery "Qry_Panel_Meeting_Date_List_Selected"
' Finish Macro
Set db = Nothing
Set qdf = Nothing
End Sub
(NOTE the DoCmd.OpenQuery is highlighted in Yellow)
strCriteria (which comes up as I hover over the IN bit of the WHERE) shows strCriteria= " '1/07/2013' " which is the correct date selected.
The Immideate debug shows...
SELECT * FROM tbl_Panel_Meeting_Dates WHERE tbl_Panel_Meeting_Dates.PanelDates IN ( '1/07/2013' );
I'm pretty sure (althiough always stand to be corrected!) that I need it to come out as
In (#1/07/2013#)
How can this be achieved please??