Link to home
Start Free TrialLog in
Avatar of Daniel Jones
Daniel Jones

asked on

Custom message box to prevent error Microsoft Office Access database engine cannot find a record in the table 'tbl_Product'with key matching field(s) 'Barcode'

I have an Access 2016 database which I use to scan barcodes to keep track of products that are already stored in the database. These products will always match the barcode number that is entered. Sometimes the wrong number gets entered from the scanner which comes up with the 3101 error.

The way that the data is scanned in is through a Subform with the field called barcode.
I would like a way to be able to show a message box to catch the error rather than the built in error on access.
Avatar of Anders Ebro (Microsoft MVP)
Anders Ebro (Microsoft MVP)
Flag of Denmark image

Well there must be some code or a macro running in your database, probably an afterUpdate event on the control in the subform. Maybe if you show that, we can make a suggestion?
Avatar of Daniel Jones
Daniel Jones

ASKER

There isn't any code or macro that is currently running on the Subform. I found a similar question with the error but do not know how it could be implemented onto my db to test that solution. Similar error
ASKER CERTIFIED SOLUTION
Avatar of Anders Ebro (Microsoft MVP)
Anders Ebro (Microsoft MVP)
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If the error is being generated by Access, you can use the forms OnError event to capture it.

 For that event, there are two arguments that are passed in:

DataErr   - This is the error number that occured.
Response - This is a variable that you set to indicate if Access should put up it's own message or not.

 Using acDataErrContinue tells Access to ignore the error and not display a message.  This would allow you to put up your own error message.    Using acDataErrDisplay is the default.

 Set the property sheet to "[Event Procedure]"   then put a STOP in the procedure.   When you execute, you'll hit the stop if Access is generating the error.   You can then look at DataErr to see what number is occurring.

 You can of course try to catch the error before it occurs with a Before or AfterUpdate event as Anders suggested and what you saw Scott suggest in the other question.

Jim.
Thank you!