Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Trapping 1

Status
Not open for further replies.

SeaRay

Technical User
Jan 8, 2002
20
0
0
US
Using Access, I have made a form to submit info. There is a required field that is only added via code by using the "submit" button.If you close the form without pushing the "submit" button, it causes an error and does not record any records. This ensures that all info will end up on all tables. If it makes one, it makes all. I have also made a messagebox that launches with "Form.On Error". It gives the error message that I wish the user to see.

However, after my messagebox is clicked OK, the built-in Access error messages also launch. Is there a way for me to prevent the built-in messages from launching?

Thanks, Rick Ruscin
 
Hi SeaRay,
Are all of your controls unbound? It sounds as if they may need to be. That way, the only way any writing is done to the table is through the Submit button's code. This is probably the cause of the Access error - it's trying to add records to a table without a required field when you just close the form using Submit.

Is this a continuous form (as opposed to "Single")? I don't believe there is a way to have an unbound form to also be a continuous form.. I usually get around this by using listboxes and edit fields.

The code for doing this is kind of long and complicated, and it uses recordset objects. But it has the advantage of being pretty nearly foolproof, if you decide to go that route.

Another option, if you really want to use continuous forms, is to bind them to a temp table (without the required submit button's field) and have the submit button run an append query to your permanent table. This should also remove the Access error.

Another option (which is somewhat more sloppy), is to figure out the number of the Access error that you're getting, and write an exception in your Form_Close's error handler:
Private Sub Form_Close()
On Error GoTo Err_Form_Close

<All other code goes here>

Exit_Form_Close:
Exit Sub

Err_Form_Close:
'IMPORTANT: Insert comment here explaining why you're
'making an exception for this particular error. You'll
'thank yourself in a year, when you no longer remember.

If Err.Number = <Insert # of error you're having here> Then
Resume Next
Else
MsgBox Err.Number,,&quot;Form_Close: &quot; & Err.Description
Resume Exit_Form_Close
End If
Exit Sub


Hope that helps! Katie
Hi! I'm currently studying the COM+ programming model. Hopefully YOU'RE having fun, which would make one of us..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top