Hello all,
I need your urgent help with this:
I found the following code on the microsoft website (Q304302) to help with creating a dynamic qbf.
The code above works only if I have just have a single criterium in each of my textboxes in my form, e.g.
ca
But when I put in:
ca or fl
It does not work. Can you please help in revising this so that it can do the above?
Thanks a lot for your help!
I need your urgent help with this:
I found the following code on the microsoft website (Q304302) to help with creating a dynamic qbf.
Code:
Private Sub cmdSearch_Click()
On Error Resume Next
Dim ctl As Control
Dim sSQL As String
Dim sWhereClause As String
'Initialize the Where Clause variable.
sWhereClause = " Where "
'Start the first part of the select statement.
sSQL = "select * from customers "
'Loop through each control on the form to get its value.
For Each ctl In Me.Controls
With ctl
'The only Control you are using is the text box.
'However, you can add as many types of controls as you want.
Select Case .ControlType
Case acTextBox
.SetFocus
'This is the function that actually builds
'the clause.
If sWhereClause = " Where " Then
sWhereClause = sWhereClause & BuildCriteria(.Name, dbtext, .Text)
Else
sWhereClause = sWhereClause & " and " & BuildCriteria(.Name, dbtext, .Text)
End If
End Select
End With
Next ctl
'Set the forms recordsource equal to the new
'select statement.
Me.txtSQL = sSQL & sWhereClause
Me.RecordSource = sSQL & sWhereClause
Me.Requery
End Sub
The code above works only if I have just have a single criterium in each of my textboxes in my form, e.g.
ca
But when I put in:
ca or fl
It does not work. Can you please help in revising this so that it can do the above?
Thanks a lot for your help!
