Creating an error message based on data in a table

76 Capri II

New member
Local time
Today, 07:29
Joined
May 5, 2016
Messages
2
I did try to search for this answer but I'm not very sure if I'm asking the question correctly.

I have a database where people enters a visitor name. We want to cause a pop up message when a user enters a visitor who isn't allowed when the "wrong" name is entered in the field and the user presses enter. If the name isn't on the list, the user can proceed with no error popup.

I know I need to create a table to enter the names

I know how to create a popup for other errors (ie too many characters in a field), but I'm not sure how to do this.

The existing database, written in Access 2002 uses a lot of VBA code. I'd imagine I need some sort of If then statement is needed,
 
effectively

Code:
 result = test for entered name in list of names
  
 if true then
    msgbox("Name Found")
 else
    msgbox("Name not found")
 end if
 
the list of names must be in a table. How do I look up in that table? Your logic seems right, but that can't be valid syntax. Is it?

I am wondering if its a query I need

Private Sub Visitor_Name_LostFocus()
If Query =True Then
msgbox("Name Found")
else

end if

That's the logic anyway.....I need help with the logic.
 
I'm not exactly sure what makes a visitor one that
isn't allowed when the "wrong" name is entered
.
However, if you have a table of NoAllowedVisitors, you could do something along these lines:

-someone enters a VisitorName into a textbox on a form(txtVisitorName)
-in the afterUpdate event of the textbox you could test to see if the name is in the NotAllowedVisitors table (let's say the field in the table is VisitorName)
--air code -- not tested-- but for logic involved

Code:
.....
If DCount("visitorName","NotAllowedVisitors","visitorName = '" & Me.txtVisitorName & "'") >0 Then

'since dcount is > 0, he/she is in the table - so not allowed
  Msgbox "This person is not allowed"
Else
  MsgBox " Good to enter"
End if
 

Users who are viewing this thread

Back
Top Bottom