Link to home
Start Free TrialLog in
Avatar of datasolutionz
datasolutionz

asked on

Custom msgbox for error Microsoft Office Access database engine cannot find a record in the table 'tblSports'with key matching field(s) 'FK_Sport'

In my Access 2007 database, I have a 'tblStudents' which has a Foreign key coming from 'tblSports', to indicate which Sport the Student plays. I have a form 'frmStudents' that I use to add/edit new students & the sport they play, which is based on a JOIN query of the two tables. When user enters a new student record & mistakenly does not select the Sport from combobox for  Sport played, i.e., combobox is empty/null and tries to navigate away from the error, the following error comes up:

Microsoft Office Access database engine cannot find a record in the table 'tblSports'with key matching field(s) 'FK_Sport'

I know the error is occuring because of Referential Integrity between tblStudents & tblSports. I would like to be able to catch/trap the error & present a custom error message so that the user knows what the issue is & waht to do, i.e., Msgbox "Please select Sport played", cmbSportPlayed.setfocus. I believe the error number is maybe 3101? I have no clue how to do this.

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America 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