Search Form SQL

L

LittlePenny

I've been trying to adapt Allen's code to create a search form. I had
success. However I would like to use "EQUALS" s instead of "LIKE" in
the line of code below. I just can get the syntax. Please help.

GCriteria = cboSearchField.value & " LIKE '*" & txtSearchString &
"*'"

Would like to use Equales





Full Code


Private Sub cmdSearch_Click()

If Len(cboSearchField) = 0 Or IsNull(cboSearchField) = True Then
MsgBox "You must select a field to search."

ElseIf Len(txtSearchString) = 0 Or IsNull(txtSearchString) = True
Then
MsgBox "You must enter a search string."

Else

'Generate search criteria
GCriteria = cboSearchField.value & " LIKE '*" &
txtSearchString & "*'"

'Filter frmCustomers based on search criteria
Form_frmRequest.RecordSource = "select * from tbl_Request
where " & GCriteria
Form_frmMonthEnd.Caption = "Request Form (" &
cboSearchField.value & " contains '*" & txtSearchString & "*')"

'Close frmSearch
DoCmd.Close acForm, "frmRequestSearch"

MsgBox "Results have been filtered."

End If

End Sub



Little Penny
 
F

fredg

I've been trying to adapt Allen's code to create a search form. I had
success. However I would like to use "EQUALS" s instead of "LIKE" in
the line of code below. I just can get the syntax. Please help.

GCriteria = cboSearchField.value & " LIKE '*" & txtSearchString &
"*'"

Would like to use Equales

Full Code

Private Sub cmdSearch_Click()

If Len(cboSearchField) = 0 Or IsNull(cboSearchField) = True Then
MsgBox "You must select a field to search."

ElseIf Len(txtSearchString) = 0 Or IsNull(txtSearchString) = True
Then
MsgBox "You must enter a search string."

Else

'Generate search criteria
GCriteria = cboSearchField.value & " LIKE '*" &
txtSearchString & "*'"

'Filter frmCustomers based on search criteria
Form_frmRequest.RecordSource = "select * from tbl_Request
where " & GCriteria
Form_frmMonthEnd.Caption = "Request Form (" &
cboSearchField.value & " contains '*" & txtSearchString & "*')"

'Close frmSearch
DoCmd.Close acForm, "frmRequestSearch"

MsgBox "Results have been filtered."

End If

End Sub

Little Penny

Is the SearchField datatype going to be a Number or Text datatype?

A Number datatype?
GCriteria = cboSearchField & " = " & txtSearchString

A Text datatype?
GCriteria = cboSearchField & " = """ & txtSearchString & """"

As .Value is a control's default property, there is no need to
explicitly write it.
 
L

LittlePenny

Thank you Fred


Little Penny







Is the SearchField datatype going to be a Number or Text datatype?

A Number datatype?
GCriteria = cboSearchField & " = " & txtSearchString

A Text datatype?
GCriteria = cboSearchField & " = """ & txtSearchString & """"

As .Value is a control's default property, there is no need to
explicitly write it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top