Replace MS Access Error with Custom Error

I

Iram

Hello.
I am using Access 2003 and I am having problems with a custom error message
box. Besides all of the data entry fields I believe there are two main vba
parts to verify then save the data from the form to the table.
The main VBA is on the "On Error" of the form. I have the following in the
[Event Procdure] not in a module.

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

'If an error occurs because of missing data in a required field
'display our own custom error message

Const conErrRequiredData = 3314

If DataErr = conErrRequiredData Then
MsgBox ("Please ensure that you enter a Calwin#, Mult Ref Y/N, CP
FirstN, CP LastN, CP Address Line 1, CP's City, CP's State, CP's Zip, NP's
FirstN, NP's LastN, Is there a Marriage, Children of this relationship and
Interview Notes")
Response = acDataErrContinue
Else
'Display a standard error message
Response = acDataErrDisplay
End If

End Sub


The other vba that I have is in a button that is used to close the data
entry form. In the [Event Procedure] of the On Click of this button I have
the following vba code...

Private Sub CloseDataEntry_Click()
If Me.Dirty Then
Me.Dirty = False
End If
DoCmd.Close

End Sub


However when I click on this button to close the form I still get the
"Run-Time error '3314' The field 'tblQuestionnaire.CP_NameF cannot contain a
Null value because the Required property for this field is set to True. Enter
a value in this field."
I know this is simple to fix. Can you help me fix this?

Iram
 
I

Iram

Thanks for replying DStegon.
I have modified the "Private Sub CloseDataEntry_Click()" according to your
specs however where and how do you want me to copy the "private function
VerifyData () as boolean" vba code to? I know that once I copy it to the
place you indicate I will have to customize it, which won't be a problem. I
am new at this stuff so if possible please provide me with easy steps.
Your help is greatly appreciated!

Iram
 
I

Iram

It worked awesome!!!!!!!!!!
You are the MAN!!!!!!!!!!!

I have tried using different flavors of code for required fields and none of
them worked like your instructions.

Thanks.
Iram/mcp



DStegon via AccessMonster.com said:
Just open up the code window (VB Window) for the form. You can copy the code
into the form object window (VB) anywhere outside another sub or function. I
would scroll to the bottom of the code window and paste it at the bottom. If
you have the form open in design mode, then you can press ALT F11 to open the
VB window. Once you have the code pasted, to assure the code does see the
function, put your cursor in the VerifyData call in the close click and press
SHIFT F2 and the your cursor will jump to the verifydata function.

Your welcome and let me know how it works.
Thanks for replying DStegon.
I have modified the "Private Sub CloseDataEntry_Click()" according to your
specs however where and how do you want me to copy the "private function
VerifyData () as boolean" vba code to? I know that once I copy it to the
place you indicate I will have to customize it, which won't be a problem. I
am new at this stuff so if possible please provide me with easy steps.
Your help is greatly appreciated!

Iram
I am assuming you are using a connected form. You should write a closing
routine to check for null values in each field before closing the form. The
[quoted text clipped - 74 lines]
 

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