From: DMWM on
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
From: Jeanette Cunningham on
The code looks to be OK.

Here is a way to debug it and find out why it doesn't work for you.

Start by commenting out all the code on the unload event.
On the Before update event, comment out all the code execpt for the code for
AmendedConatctName.

When the code works for AmendedContactName, then add in the code for
AmendedContactAddress1.
When that is working, add in the code for the next control and continue in
this way, testing and only when the code works, add in the code for the next
control.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


"DMWM" <DMWM(a)discussions.microsoft.com> wrote in message
news:5D7BAC29-A65C-443A-8AEA-B49146290C88(a)microsoft.com...
> 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