"Call Form_Error" function error

T

Tom

I exectue an OnError function on a FORM. However, this
function is only execute when I click "Close Window".

Instead, I'd like to click on a command button (let's
call it "Save Record") and execute the FORM's OnError via
the SaveRecord function.

In a previous thread, I was suggested to use the call
function. However, line of code appears red in the
SaveRecord function.

Here's what I have:

Private Sub Form_Error(DataErr As Integer, Response As
Integer)

.... code with personalized error message
End Sub



Private Sub SaveRecord_Click()

Call Form_Error(DataErr As Integer, Response As Integer)

End Sub


Again, the Call Form_Error line appears red in my
SaveRecord Function. What am I doing wrong?


Tom
 
D

Dan Artuso

Hi,
The sub expects two arguments which you have to supply.
So, you have to know the error number that you want raise.
Or I suppose you could just enter any error number and supply your own message,
but this might interfere with the normal working of the sub.

So, you could call it like this:
Call Form_Error(2279, acDataErrContinue)

2279 is incorrect data format for a particular input mask.
 
T

Tom

Dan:

Thanks for the feedback...

Unfortunately, this is not working exactly as expected.

Although, I now can execute the function without bringing
up the VBA debugging window, the "error message" is NOW
ALWAYS executed (even if there is no error).

The error message should pop only up if someone intends to
enter a duplicate value into a textbox.

It works fine with the OnError form event only. However,
the second function (via OnClick of a COMMAND BUTTON) does
not call the Form OnError event properly.

Any additional suggestions?

Thanks,
Tom
 
D

Dan Artuso

Hi,
Yes well you'll have to pass the correct error number to the Sub.
I've no idea what code you have in the OnError event. Are displaying a custom message?
To get the number, force the error (don't call it from your button) and display a message box:
MsgBox DataErr
from within the OnError event.

Now you know what to pass it. Does that help?
 
T

Tom

The error number is 3022. I saw the procedure as to how
I get the error number in a different threat.

Still, the remaining problem is that I always execute the
error message... it throws the error even when proper
data is entered.

Tom

-----Original Message-----
Hi,
Yes well you'll have to pass the correct error number to the Sub.
I've no idea what code you have in the OnError event.
Are displaying a custom message?
To get the number, force the error (don't call it from
your button) and display a message box:
 
D

Dan Artuso

I'm a bit confused now. By calling the OnError function you will
obviously want to raise some error, no? Else why call it?
If you only want to call it if the data is incorrect, then you'll have to
check the data yourself from code.

Why do you want to manually call it instead of letting Access call it
when the data is incorrect?

I re-read your first post. Why not force the form to save the data in your command
button code, then if the data is incorrect, Access will call the form's OnError
Just use this code:
Me.Dirty = False
 

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