Create an Message Box pop up when criteria is not met

K

ktfrubel

Hello,
I have a parameter query that ask for a First name and a last name. I would
like for an message to appear if no one by the names appear. I can't seem to
find anything in the discussions.

Example:
Enter First Name:
Frank
Enter Second Name
Smith

Message pops up if there is no Frank Smith in the database and Says oops
sorry try again.


Can anyone help me....I need to have t his completed by monday, and I am at
my whits ends.


Thanks
Tara
 
K

ktfrubel

I apologize....This is not for a homework assignment. I have a form that
will be used for data entry. First step is to search for existing names
before entering a new one. If the criteria is not me, I would like the
message box to appear.
This is not a homework assignment. If it were, I would probalbly have a
text book to help me along.
 
J

JK

Untested

Private Sub Form_BeforeUpdate()

'Test That both names are entered
If IsNull(Me.First_Name) Then
MsgBox "Ooops First Name must be eneterd"
DoCmd.CancelEvent
End If
If IsNull(Me.Second_Name) Then
MsgBox "Ooops Second Name must be eneterd"
DoCmd.CancelEvent
End If

'Test For duplicate
If Nz((Dlookup("[NamesID]","[tblNames]","[First Name]=' " &
Me.First_Name _
&" ' AND [Second Name]= ' " & Me.Second_Name _
& " ' AND NOT [NamesID]= " & Nz(Me.NamesID,0)),0)<>0 Then
'(remove the spaces inside ' " and " ' )

MsgBox "Ooops, " & Me.First_Name & " " & Me.Second_Name _
& " already exists, please try again"
DoCmd.CancelEvent
End If

End Sub

Regards/JK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top