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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to show a message box when criteria doesn't match

Status
Not open for further replies.

OldSlowDog

Programmer
Mar 11, 2002
36
US
I use the following openform with a criteria:
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormReadOnly

My question is that I got a blank screen when there is nothing in the DB matching the criteria.

If possible, I like to display a message saying"
Msgbox "No matching Record"

Would some experts show me how to tell such "no matching record" condition in VBA.

Appreciate very much.
 
Try looking up the HasData property in the Help File.
 
edpoon,

try this....

dim x as string
Set rs = CurrentDb.OpenRecordset("tblname")
x = False
Do While Not rs.EOF
If Trim(txtname) = Trim(rs!tblfield) Then
x = True
Exit Do
End If
rs.MoveNext
Loop
If x = True Then

stDocName = "frmname"
stLinkCriteria = "[tblfield]=" & "'" & Me![txtname] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Else
MsgBox "Record not Found"

End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top