hgus393
Registered User.
- Local time
- Today, 07:33
- Joined
- Jan 27, 2009
- Messages
- 83
Hi all,
I have some code that I found on the net for searching on a form using a listbox. I also have in my form a text box that I would like to use in conjunction with the list box. I have the following code:
This returns in the Immediate window:
SELECT * FROM QueryFindWithDatesQ WHERE [QueryFindWithDatesQ].[CLEANNAME] = "JANE" AND QueryFindWithDatesQ.[Per Date] = "2011-01-31" Or "[QueryFindWithDatesQ].[CLEANNAME] = "BOB" AND QueryFindWithDatesQ.[Per Date] = "2011-01-31;
The problem is the starting " after the OR (I Believe???)
Does anyone know how to remove that " ?
Bob
I have some code that I found on the net for searching on a form using a listbox. I also have in my form a text box that I would like to use in conjunction with the list box. I have the following code:
Code:
Private Sub Command26_Click()
'Declare variables
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim varItem As Variant
Dim varItem1 As Variant
Dim strCriteria As String
Dim strSQL As String
' Get the database and stored query
Set db = CurrentDb()
Set qdf = db.QueryDefs("QueryFindWithDates>Q")
' Loop through the selected items in the list box and build a text string
If Me!InstrLista.ItemsSelected.Count > 0 Then
For Each varItem In Me!InstrLista.ItemsSelected
strCriteria = strCriteria & "[QueryFindWithDatesQ].[CLEANNAME] = " & Chr(34) _
& Me!InstrLista.ItemData(varItem) & Chr(34) & " AND QueryFindWithDatesQ.[Per Date] = " & Chr(34) & [Forms]![DAD]![Per Date] & """ Or """
Next varItem
strCriteria = Left(strCriteria, Len(strCriteria) - 6)
Else
strCriteria = "[QueryFindWithDates>Q].[CLEANNAME] Like '*'"
End If
Debug.Print strSQL
' Apply the new SQL statement to the query
qdf.sql = strSQL
' Open the query
DoCmd.OpenQuery "QueryFindWithDates>Q"
' Empty the memory
Set db = Nothing
Set qdf = Nothing
End Sub
This returns in the Immediate window:
SELECT * FROM QueryFindWithDatesQ WHERE [QueryFindWithDatesQ].[CLEANNAME] = "JANE" AND QueryFindWithDatesQ.[Per Date] = "2011-01-31" Or "[QueryFindWithDatesQ].[CLEANNAME] = "BOB" AND QueryFindWithDatesQ.[Per Date] = "2011-01-31;
The problem is the starting " after the OR (I Believe???)
Does anyone know how to remove that " ?
Bob