goodhvnting
Registered User.
- Local time
- Today, 11:36
- Joined
- Sep 8, 2016
- Messages
- 10
Hello!
This is my second post in this awesome community. My first question was solved and now I am back hoping to learn more.
Problem:
I created a continuous form that has check boxes and a search box. My check box filters out results based on what is selected, and my search box can search multiple fields. Everything was working perfect until it was decided that using a subform/datasheet view is more user friendly than a continuous form. I created a new form with a subform and used the same code but now the search box will not search any fields. My check boxes work fine but the search box is not.
Hopeful Outcome:
I would like my search box to search multiple fields using keywords but at the same time follow the rules of my checkboxes with my search results populating the subform within my form. Could someone take a look at my code? Currently the checkboxes work but the search box does not. Cheers
Here is my code:
Property Get WhereLocation() As String
' construct a partial where clause based on check box settings
Dim tmp As String
If Me.chkCRM2 Then tmp = " OR LocationID = 1 "
If Me.chkRRM2 Then tmp = tmp & " OR LocationID = 2 "
If tmp <> "" Then WhereLocation = Mid(tmp, 5) 'drop the leading " OR "
End Property
Property Get WhereTextSearch() As String
' construct a partial where clause based on Me.txtSearch, if present
If Not IsNull(Me.txtSearch2) Or Me.txtSearch2 = "" Then
WhereTextSearch = _
"(Title like ""*" & Me.txtSearch2 & "*"") " & _
"Or (Keywords like ""*" & Me.txtSearch2 & "*"") " & _
"Or (Comments like ""*" & Me.txtSearch2 & "*"")"
End If
End Property
Property Get WhereClause() As String
' Construct a final WHERE clause from the two partials, above
Dim loc As String
Dim txt As String
loc = Me.WhereLocation
txt = Me.WhereTextSearch
If Len(loc) > 0 And Len(txt) > 0 Then
'if both exist, we AND them together
WhereClause = " WHERE (" & loc & ") AND (" & txt & ") "
ElseIf Len(loc & txt) > 0 Then
'otherwise we just use the one that exists
WhereClause = " WHERE " & loc & txt & " "
Else
'otherwise, there is no where clause, and we return an empty string
End If
End Property
Private Sub Command11_Click()
Me.RecordSource = _
"SELECT * FROM tblResourceRoom " & _
Me.WhereClause
End Sub
Private Sub Command12_Click()
Me.RecordSource = _
"SELECT * FROM tblResourceRoom " & _
Me.WhereClause
End Sub
Private Sub Command18_Click()
Me.chkCRM2 = False
Me.chkRRM2 = False
End Sub
Private Sub Command19_Click()
Me.chkCRM2 = True
Me.chkRRM2 = True
End Sub
This is my second post in this awesome community. My first question was solved and now I am back hoping to learn more.
Problem:
I created a continuous form that has check boxes and a search box. My check box filters out results based on what is selected, and my search box can search multiple fields. Everything was working perfect until it was decided that using a subform/datasheet view is more user friendly than a continuous form. I created a new form with a subform and used the same code but now the search box will not search any fields. My check boxes work fine but the search box is not.
Hopeful Outcome:
I would like my search box to search multiple fields using keywords but at the same time follow the rules of my checkboxes with my search results populating the subform within my form. Could someone take a look at my code? Currently the checkboxes work but the search box does not. Cheers

Here is my code:
Property Get WhereLocation() As String
' construct a partial where clause based on check box settings
Dim tmp As String
If Me.chkCRM2 Then tmp = " OR LocationID = 1 "
If Me.chkRRM2 Then tmp = tmp & " OR LocationID = 2 "
If tmp <> "" Then WhereLocation = Mid(tmp, 5) 'drop the leading " OR "
End Property
Property Get WhereTextSearch() As String
' construct a partial where clause based on Me.txtSearch, if present
If Not IsNull(Me.txtSearch2) Or Me.txtSearch2 = "" Then
WhereTextSearch = _
"(Title like ""*" & Me.txtSearch2 & "*"") " & _
"Or (Keywords like ""*" & Me.txtSearch2 & "*"") " & _
"Or (Comments like ""*" & Me.txtSearch2 & "*"")"
End If
End Property
Property Get WhereClause() As String
' Construct a final WHERE clause from the two partials, above
Dim loc As String
Dim txt As String
loc = Me.WhereLocation
txt = Me.WhereTextSearch
If Len(loc) > 0 And Len(txt) > 0 Then
'if both exist, we AND them together
WhereClause = " WHERE (" & loc & ") AND (" & txt & ") "
ElseIf Len(loc & txt) > 0 Then
'otherwise we just use the one that exists
WhereClause = " WHERE " & loc & txt & " "
Else
'otherwise, there is no where clause, and we return an empty string
End If
End Property
Private Sub Command11_Click()
Me.RecordSource = _
"SELECT * FROM tblResourceRoom " & _
Me.WhereClause
End Sub
Private Sub Command12_Click()
Me.RecordSource = _
"SELECT * FROM tblResourceRoom " & _
Me.WhereClause
End Sub
Private Sub Command18_Click()
Me.chkCRM2 = False
Me.chkRRM2 = False
End Sub
Private Sub Command19_Click()
Me.chkCRM2 = True
Me.chkRRM2 = True
End Sub