I have created a Parameter Query Form with 3 drop down criteria fields (1-Product, 2-Failure Mode, 3-Failure Mechanism). The 'row source' for the drop down fields are from another query.
The issue I am having is that sometimes one or two of the drop down fields will be left blank. If any of the drop down fields are left blank the query results are blank. I would like to change the below Visual Basic code to allow Null for the drop downs and still run a search. Note that when all of the drop downs are filled out the query runs properly. Below is the code I initially tried:
Private Sub OK___Search_Click()
On Error GoTo Err_OK___Search_Click
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o> </o>
Dim stDocName As String
Dim stLinkCriteria As String
<o> </o>
stDocName = "frm-QIT Details"
stLinkCriteria = "[Failure Mechanism]=" & "'" & Me![FailureMechanism] & "'" & "AND [Failure Mode]=" & "'" & Me![FailureMode] & "'" & "AND [Product]=" & "'" & Me![Product] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
<o> </o>
Exit_OK___Search_Click:
Exit Sub
<o> </o>
Err_OK___Search_Click:
MsgBox Err.Description
Resume Exit_OK___Search_Click
End Sub
_________________________________
I then tried the following code with the same result (blank query results if any of the drop downs are left blank)
Private Sub OK___Search_Click()
On Error GoTo Err_OK___Search_Click
<o> </o>
Dim stDocName As String
Dim stLinkCriteria As String
<o> </o>
stDocName = "frm-QIT Details"
If IsNull(Me![FailureMode]) Then
stLinkCriteria = "[Product]=" & "'" & Me![Product] & "'"
End If
If IsNull(Me![FailureMechanism]) Then
stLinkCriteria = "[Failure Mode]=" & "'" & Me![FailureMode] & "'" & "AND [Product]=" & "'" & Me![Product] & "'"
End If
stLinkCriteria = "[Failure Mechanism]=" & "'" & Me![FailureMechanism] & "'" & "AND [Failure Mode]=" & "'" & Me![FailureMode] & "'" & "AND [Product]=" & "'" & Me![Product] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
<o> </o>
Exit_OK___Search_Click:
Exit Sub
<o> </o>
Err_OK___Search_Click:
MsgBox Err.Description
Resume Exit_OK___Search_Click
End Sub
______________________________
I appreciate any help you can provide.
The issue I am having is that sometimes one or two of the drop down fields will be left blank. If any of the drop down fields are left blank the query results are blank. I would like to change the below Visual Basic code to allow Null for the drop downs and still run a search. Note that when all of the drop downs are filled out the query runs properly. Below is the code I initially tried:
Private Sub OK___Search_Click()
On Error GoTo Err_OK___Search_Click
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o> </o>
Dim stDocName As String
Dim stLinkCriteria As String
<o> </o>
stDocName = "frm-QIT Details"
stLinkCriteria = "[Failure Mechanism]=" & "'" & Me![FailureMechanism] & "'" & "AND [Failure Mode]=" & "'" & Me![FailureMode] & "'" & "AND [Product]=" & "'" & Me![Product] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
<o> </o>
Exit_OK___Search_Click:
Exit Sub
<o> </o>
Err_OK___Search_Click:
MsgBox Err.Description
Resume Exit_OK___Search_Click
End Sub
_________________________________
I then tried the following code with the same result (blank query results if any of the drop downs are left blank)
Private Sub OK___Search_Click()
On Error GoTo Err_OK___Search_Click
<o> </o>
Dim stDocName As String
Dim stLinkCriteria As String
<o> </o>
stDocName = "frm-QIT Details"
If IsNull(Me![FailureMode]) Then
stLinkCriteria = "[Product]=" & "'" & Me![Product] & "'"
End If
If IsNull(Me![FailureMechanism]) Then
stLinkCriteria = "[Failure Mode]=" & "'" & Me![FailureMode] & "'" & "AND [Product]=" & "'" & Me![Product] & "'"
End If
stLinkCriteria = "[Failure Mechanism]=" & "'" & Me![FailureMechanism] & "'" & "AND [Failure Mode]=" & "'" & Me![FailureMode] & "'" & "AND [Product]=" & "'" & Me![Product] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
<o> </o>
Exit_OK___Search_Click:
Exit Sub
<o> </o>
Err_OK___Search_Click:
MsgBox Err.Description
Resume Exit_OK___Search_Click
End Sub
______________________________
I appreciate any help you can provide.