How do I eliminate double error messages

C

Cheese_whiz

Hi all,

I've run into this before and worked around it, but I'm hoping someone can
give me a better way to deal with it....

If I put code on a button to save a record, and I have code in my
beforeupdate event of the form that validates data and throws an error
message (setup by me) if something is wrong, then I end up with two error
messages: 1 that I set up and another one from access. It basically works
like this:

1. Code begins running in click event of button.
2. Code jumps to beforeupdate event and throws my error message.
3. Code goes back to button's click event and throw's access' error message.

In the past, I've used a select case in the error handler to just ignore the
error access throws.

Is there a better way?

Thanks,
CW
 
D

Douglas J. Steele

Are you remembering to issue a Resume xxx (where xxx is some label in your
code) or Err.Clear after you've reported the error in your BeforeUpdate
event?
 
C

Cheese_whiz

Hi Douglas,

Hrm, not really sure how that works, so technically I'm not forgetting it :)

I'll throw some code out and maybe you can copy/paste/modify?

Private Sub cmdSave_Click()

On Error GoTo cmdSave_Click_Error

'save w/o warning
varShowWarnings = False
Call subSaveData(Me)
varShowWarnings = True

If Me.NewRecord Then
Me.cmdAddFileMailEntity.Enabled = False
Else
Me.cmdAddFileMailEntity.Enabled = True
End If


Exit_cmdSave_Click:
Exit Sub

cmdSave_Click_Error:

Call LogError(err.Number, err.Description, "cmdSave_Click", Me.Name, ,
True)

End Sub
-----------------------------------------------------

Private Sub Form_BeforeUpdate(Cancel As Integer)

On Error GoTo Form_BeforeUpdate_Error

If IsNull(Me.txtDescription) Or Len(Me.txtDescription) < 1 Then
MsgBox "You must add a description in order to save the mail item!",
vbOKOnly, "Error: Description Omitted!"
Cancel = True
Me.txtDescription.SetFocus
End If

Exit_Form_BeforeUpdate:
Exit Sub

Form_BeforeUpdate_Error:

Call LogError(err.Number, err.Description, "Form_BeforeUpdate", Me.Name,
, True)

End Sub
--------------------------------------------

Note: the subSaveData() is just a simple procedure that utilizes the If
Me.dirty along with a way to turn the warnings off so the save comes without
messages.

Thanks for your help,
CW
 
D

Douglas J. Steele

Easiest would be to put

Resume Exit_cmdSave_Click

in the cmdSave_Click sub after the call to LogError, before the End Sub, and

Resume Exit_Form_BeforeUpdate

in the Form_BeforeUpdate sub after the call to LogError, before the End Sub.
 
C

Cheese_whiz

Thanks, Douglas,

Adding those lines didn't do anything noticeable. I still get my data
validation msg box from the beforeupdate and then one related to the cmdSave
button.

I think I need some way to stop all code immediately whereas I think I only
know how to stop the beforeupdate procedure which sends the code back to that
subSaveData procedure.

Thanks again for the reply.
CW
 
J

JvC

Add an Err.Clear at the end of your LogError routine

John

Cheese_whiz formulated on Thursday :
 
C

Cheese_whiz

Thanks for the reply, JvC,

I put Resume Next above the LogError line in my error handler in the cmdSave
procedure, and added err.Clear below the LogError line in my beforeupdate
procedure.

It works, and if I walk through the code line by line as it executes it
appears to just eliminate that second error message without changing anything
else about the way the code runs, but I dont' know why and I'm not positive I
haven't lost something else in terms of error functionality in the process.

Thanks again,
CW
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top