Validate data enterred into a field on a form against a value in another table

I have a form that contains a field titled BarCode. This field is bound to a table call it Table-AAA. When the user enters a number into the barcode field I want the application to validate that the number the user entered into the Barcode Field  is a number listed in TABLE-BBB. If it is not a valid value I will pop up an error message. The name of the field in Table-BBB to use in the validation process is "AssetNbr".

I know that this VBA code will be placed on the After-Update event of the BarCode field but I do not know how to create this code.

Any Code suggestions on how to do this?

Thanks in advance for your suggestions.

Lou
LVL 1
Lou DufresneIT Business Analyst CSM / Project ManagerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

shanesuebsahakarnCommented:
You could do this:

If IsNull(DLookup("[AssetNbr]","Table-BBB","[AssetNbr]='" & Me!BarCode & "'")) Then
   'Record doesn't exist in bbb
Else
   'It does
End If

However, you can achieve the same thing by enforcing referential integrity between tables AAA and BBB. This would force the AAA record to have a related record in BBB, if that is what you want to achieve. The above code btw assumes that the field is text - if it is a numeric field, remove the apostrophe ' characters.
0
MikeAHoganCommented:
BarCode_AfterUpdate()

if dcount("[IDFIELD]", "TABLE-BBB", "[AssetNbr] = '" & me!BarCode & "'") = 0 then
     msgbox "Enter your error code here"
Else
     'it is in the list
endif

End sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Lou DufresneIT Business Analyst CSM / Project ManagerAuthor Commented:
Thank you both for your expert help.

Lou Dufresne
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.