M22664
04-02-2010, 11:30 AM
I have a new Access database I'm working on. There is a form called ProjectForm that is used for entering project specific information. The information entered goes to a table called ProjectTable. At the bottom of that ProjectForm is a button that reads "Search Projects" when you click on that button a Search Form pops up called frmSearch. The Search Form has three combo boxes and three texted boxes where the user can enter three different search fields and search strings to search all the projects in the database to see for example how many projects we used a certain widget. At the bottom of the Search Form is a button that reads "Search". The code below is the Event associated with the "Search" button. My problem is the search does not work when search fields and search strings are entered in all three combo boxes and text boxes. It only works when search criteria is selected with the first combo box/text box.
Can you look at the code below and determine what the problem is.
Thank you.
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 & "*'"
'GCriteria = cboSearchField2.Value & " LIKE '*" & txtSearchString2 & "*'"
'GCriteria = cboSearchField3.Value & " LIKE '*" & txtSearchString3 & "*'"
'Filter ProjectForm based on search criteria
Form_ProjectForm.RecordSource = "select * from ProjectTable where " & GCriteria
Form_ProjectForm.Caption = "ProjectTable (" & cboSearchField.Value & " contains '*" & txtSearchString & "*')"
'Form_ProjectForm.Caption = "ProjectTable (" & cboSearchField2.Value & " contains '*" & txtSearchString2 & "*')"
'Form_ProjectForm.Caption = "ProjectTable (" & cboSearchField3.Value & " contains '*" & txtSearchString3 & "*')"
'Close frmSearch
DoCmd.Close acForm, "frmSearch"
MsgBox "Results have been filtered."
End If
End Sub
Can you look at the code below and determine what the problem is.
Thank you.
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 & "*'"
'GCriteria = cboSearchField2.Value & " LIKE '*" & txtSearchString2 & "*'"
'GCriteria = cboSearchField3.Value & " LIKE '*" & txtSearchString3 & "*'"
'Filter ProjectForm based on search criteria
Form_ProjectForm.RecordSource = "select * from ProjectTable where " & GCriteria
Form_ProjectForm.Caption = "ProjectTable (" & cboSearchField.Value & " contains '*" & txtSearchString & "*')"
'Form_ProjectForm.Caption = "ProjectTable (" & cboSearchField2.Value & " contains '*" & txtSearchString2 & "*')"
'Form_ProjectForm.Caption = "ProjectTable (" & cboSearchField3.Value & " contains '*" & txtSearchString3 & "*')"
'Close frmSearch
DoCmd.Close acForm, "frmSearch"
MsgBox "Results have been filtered."
End If
End Sub