I have a condition that to the application owners of an Access app is an error condition. If they try to import a parts file and the part pricing isn’t in the part pricing table already, it should stop the import and tell the user to add the pricing information before importing the file.
The actual table doesn’t require the field and I am able to import it technically without the information, so in this case, I’m determining that this is simply a domain level undesirable event.
You need to have an error handler active in your routine. In Access VBA that means you use:
On Error Goto LABEL
And then you specify the LABEL elsewhere in the routine (usually towards the bottom). If an error occurs of any kind after the On Error Goto clause, the VBA will be in an error condition and goto the label you’ve specified where you can then handle the error.
In my case the program flow goes Select File to Import -> Click on Import button -> Import the file to a staging area first -> Copy the Staged data to the Live table.
I want to trigger my error after staging the data and before sending it to the Live table. If there are any parts in the staged table with no pricing records, I use:
Err.Raise MyErrNumber
To raise the error and prevent the process from finishing, displaying a report with the information the user will need to enter the pricing before they try again.