form closing problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi I have a validation on a form with the following code:


Dim Myctl As Control

For Each Myctl In Me.Controls
Select Case Myctl.ControlType
Case acComboBox, acTextBox
If IsNull(Myctl) Or Myctl = "" Then
MsgBox "Please complete all fields in this form.",
vbInformation, "Data Error:"
Myctl.SetFocus
Cancel = True
Exit Sub
End If
End Select
Next


Problem: The message box appears if I leave any field blank but as soon as I
click Okay, it will automatically close the form without me correcting the
mistake. Please help if I missed anything.

code on close button:
On Error GoTo Err_cmdClose_Click


DoCmd.Close

Exit_cmdClose_Click:
Exit Sub

Err_cmdClose_Click:
MsgBox Err.Description
Resume Exit_cmdClose_Click
 
Did you place this code on the before update event of the form?
If not, try it there.

If that not the case, does this code placed on a sub form?
 
Hi,
This code is placed on the before update event of a form not
a subform.
Thanks in advance.
 
Back
Top