form closing problem

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
 
G

Guest

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?
 
G

Guest

Hi,
This code is placed on the before update event of a form not
a subform.
Thanks in advance.
 

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