moonsmile66
New member
- Local time
- Today, 16:15
- Joined
- May 12, 2010
- Messages
- 6
Hi guys/gals,
I have been forced to use Access to build a project database for my group not long ago. I didn't have any Access or programming experiences before so please bare with me if I'm asking silly questions.
Brief background:
Bunch tables to store the data; bunch forms for data entering; a form and query for search. I built the search form following an old example I found from this forum.
Question:
For the search form, the logic of searching by "Process #1" and "Process #2" are not working correct. Coding as below.
I'm trying to search the record which contains "comP1" entry in either [Process #1] or [Process #2], and this criteria has to be combined with other criteria. Same wish for "comP2"
The problem is both searching with "Process #1" and "Process #2" are not doing "AND" with other criteria, need help!
Thanks many!
I have been forced to use Access to build a project database for my group not long ago. I didn't have any Access or programming experiences before so please bare with me if I'm asking silly questions.
Brief background:
Bunch tables to store the data; bunch forms for data entering; a form and query for search. I built the search form following an old example I found from this forum.
Question:
For the search form, the logic of searching by "Process #1" and "Process #2" are not working correct. Coding as below.
I'm trying to search the record which contains "comP1" entry in either [Process #1] or [Process #2], and this criteria has to be combined with other criteria. Same wish for "comP2"
The problem is both searching with "Process #1" and "Process #2" are not doing "AND" with other criteria, need help!
Thanks many!
Code:
Private Sub btnSearch_Click()
' Update the record source
Me.frmsubSearch.Form.RecordSource = "SELECT * FROM Query1 " & BuildFilter
' Requery the subform
Me.frmsubSearch.Requery
End Sub
Private Function BuildFilter() As Variant
Dim varWhere As Variant
Dim intIndex As Integer
varWhere = Null ' Main filter
' Check for LIKE State
If Me.comState > "" Then
varWhere = varWhere & "[State] LIKE """ & Me.comState & "*"" AND "
End If
' Check for LIKE Source Water
If Me.comSourceWater > "" Then
varWhere = varWhere & "[SourceWater] LIKE """ & Me.comSourceWater & "*"" AND "
End If
' Check for min design flow
If Me.txtlowflow > "" Then
varWhere = varWhere & "[Designflow] > " & Me.txtlowflow & " AND "
End If
' Check for max design flow
If Me.txthighflow > "" Then
varWhere = varWhere & "[Designflow] < " & Me.txthighflow & " AND "
End If
' Check for process #1
If Me.comP1 > "" Then
varWhere = varWhere & "[Process #1] LIKE """ & Me.comP1 & "*"" OR [Process #2] LIKE """ & Me.comP1 & "*"" AND "
End If
' Check for process #2
If Me.comP2 > "" Then
varWhere = varWhere & "[Process #1] LIKE """ & Me.comP2 & "*"" OR [Process #2] LIKE """ & Me.comP2 & "*"" AND "
End If
' Check if there is a filter to return...
If IsNull(varWhere) Then
varWhere = ""
Else
varWhere = "WHERE " & varWhere
' strip off last "AND" in the filter
If Right(varWhere, 5) = " AND " Then
varWhere = Left(varWhere, Len(varWhere) - 5)
End If
End If
BuildFilter = varWhere
End Function