Pop up form closing too soon - required/validation coding

D

DMWM

Hi All,

I have a pop up form that loads from the afterupdate event of a combo box
depending on the result. The information in the pop up form is held in the
same table as the combo box that is updated (I'm not sure if this will affect
the code I am after but i thought it should be mentioned and this cannot be
changed due to the customers' requirements...unfortunately)

I have so far coded so that when a field is set to visible it is required
and if not entered a custom message box appears. The problem I am having is
that when the error comes up lets say for the second field in the code
(AmendedContactAddress1) the code stops running so that the field can be
entered. When the field is entered and the form is then closed without any of
the other required fields being entered no error is displayed and the form
closes.

I should mention that this code was originally in the Beforeupdate event of
the form but did not seem to work so after some searching through the forum I
tried it the On Unload event which is currently working.

Should the code be in both?

The first part of the code is pasted below, it follows a basic pattern with
changed field names for the rest that is not shown:

If AmendedContactName.Visible Then

If IsNull(Me.AmendedContactName) Then
MsgBox "Contact Name must be entered.", vbExclamation, "Incomplete
data."
Cancel = True
Me.AmendedContactName.SetFocus
End If

ElseIf AmendedContactAddress1.Visible Then

If IsNull(Me.AmendedContactAddress1) Then
MsgBox "Contact Address 1 must be entered.", vbExclamation,
"Incomplete data."
Cancel = True
Me.AmendedContactAddress1.SetFocus
End If

ElseIf AmendedContactAddress2.Visible Then

If IsNull(Me.AmendedContactAddress2) Then
MsgBox "Contact Address 2 must be entered.", vbExclamation,
"Incomplete data."
Cancel = True
Me.AmendedContactAddress2.SetFocus
End If
(etc...until last then End If obviously)

Any help would be greatly appreciated

DMWM
 

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