Search Form Not Working for All Filter Input

aball65

Registered User.
Local time
Today, 14:49
Joined
Oct 14, 2004
Messages
44
The following VBA code is out of a search form used to collect user search criteria and then query based on the input criteria. The RiskID portion of the filter is not working. For example, the Debug.Print shows the where clause equal to "1=1 AND RISK.[r_id] = 11" if the user enters a Risk ID of 11. However, the form continues to display all risks (e.g., IDs 1,2,3, .... 11) and prompts the user to "Enter Parameter Value RISK.r_id" which I don't understand. The form works/filters based on user input Risk Level values.

Option Compare Database
Option Explicit

Private Sub Clear_Click()
DoCmd.Close
DoCmd.OpenForm "RISK_S"
End Sub

Private Sub Search_Click()
Dim strWhere As String
Dim strError As String

strWhere = "1=1"

' If RiskId
If Not IsNull(Me.Lid) Then
'Create Predicate
strWhere = strWhere & " AND " & "RISK.[r_id] = " & Me.Lid & ""
End If

' If Level
If Not IsNull(Me.Llevel) Then
'Add the predicate
strWhere = strWhere & " AND " & "RISK.[rl_id] = " & Me.Llevel & ""
End If


Debug.Print "Value of strWhere is " & strWhere

If strError <> "" Then
MsgBox strError
Else
'DoCmd.OpenForm "Browse Risks", acFormDS, , strWhere, acFormEdit, acWindowNormal
If Not Me.FormFooter.Visible Then
Me.FormFooter.Visible = True
DoCmd.MoveSize Height:=Me.WindowHeight + Me.FormFooter.Height
End If
Me.Browse_All_Risks.Form.Filter = strWhere
Me.Browse_All_Risks.Form.FilterOn = True
End If
End Sub


Not sure if there is enough code here for anyone to assist or not.

Thanks.
 
Fixed it. The associated select statement used aliases. I updated the VBA to reference the aliases and it now works.
 

Users who are viewing this thread

Back
Top Bottom