Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Attached To Query 1

Status
Not open for further replies.

smdemo

Programmer
Sep 15, 2002
63
US
I'll try to be as clear as I can as to what I am trying to do. I have a form that is linked to a query. That same query is attached to another form (dialog box) where the user will enter a SSN to search for. That value is passed to the query and will open the final form with all matching records with that SSN. My question is how and where would I code a pop up box if no matches are found? Currently what is happening is just a blank screen appears which makes since since the query returned nothing. I know I can just activate the control and close buttons on the form but I would prefer a popup and not open the form if there are no matches. I hope this was clear enough. Thanks for any help anyone can provide.

Thanks
Steve
 
Try something like this:

Code:
Private Sub Form_Open(Cancel As Integer)
Dim strRecError

If Me.RecordSource <> "" Then
    If Me.Recordset.RecordCount = 0 Then
        strRecError = "No Records. "
    End If
Else
    strRecError = "No recordset. "
End If
If strRecError <> "" Then
    If MsgBox(strRecError & "Continue?", vbYesNo) = vbNo Then
        Cancel = True
    End If
End If
End Sub
 
Great, thank you so much. It was the Cancel part that I was missing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top