I have the following code which uses a form that has (two date boxes and two comboboxes) to allow the user to select criteria for a query result. It all works fine except when no records are found with that criteria. The query still opens with no records.
Question is, how can I insert a msgbox saying "no matching records found" prior to the query/and eventually a report, opening?
Question is, how can I insert a msgbox saying "no matching records found" prior to the query/and eventually a report, opening?
Code:
Private Sub cmdSearch_Click() If IsNull([cboCustomer]) And IsNull([SDate]) And IsNull([EDate]) And IsNull([cboIssue]) Then MsgBox "No Search Criteria Selected", vbDefaultButton1 = vbOKOnly, "Insufficient Search Critera" Else If Not IsNull([cboCustomer]) And IsNull([SDate]) And IsNull([EDate]) And IsNull([cboIssue]) Then MsgBox "You must select a date range or issue type to continue", vbDefaultButton1 = vbOKOnly, "Insufficient Search Critera" Else: If IsNull([cboCustomer]) And Not IsNull([SDate]) And Not IsNull([EDate]) And IsNull([cboIssue]) Then MsgBox "You must select a VIP or issue type to continue", vbDefaultButton1 = vbOKOnly, "Insufficient Search Critera" Else If Not IsNull([cboCustomer]) And Not IsNull([SDate]) And Not IsNull([EDate]) And IsNull([cboIssue]) Then DoCmd.OpenQuery "qryWalkthrough", acViewNormal, acViewNormal Else If Not IsNull([cboCustomer]) And IsNull([SDate]) And IsNull([EDate]) And Not IsNull([cboIssue]) Then DoCmd.OpenQuery "qryWalkthrough", acViewNormal Else If IsNull([cboCustomer]) And Not IsNull([SDate]) And Not IsNull([EDate]) And Not IsNull([cboIssue]) Then DoCmd.OpenQuery "qryWalkthrough", acViewNormal Else If Not IsNull([cboCustomer]) And Not IsNull([SDate]) And Not IsNull([EDate]) And Not IsNull([cboIssue]) Then MsgBox "Please remove one search criteria", vbDefaultButton1 = vbOKOnly, "To many Critera fields chosen" End If End If End If End If End If End If End If End Sub
Comment