G
Guest
Hi
I have a form with required fileds which works great unleess someone want to
force close the form.
THis is part of the code which I am using
/////////////////////////////////////////////////////////////////////
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull([CL_KEY]) Then
Beep
MsgBox "The Client Key Is A Required Field - Please Enter The Correct
Client Key"
Cancel = True
DoCmd.GoToControl "CL_KEY"
Else
If IsNull([CL_FORMAL_NAME]) Then
Beep
response = MsgBox("The Formal Name Is A Required Field - Please
Enter The Correct Formal Name" & Chr(13) & "Do You Wish To Cancel Set Up?",
vbYesNo)
If response = vbYes Then
Cancel = True
Else
DoCmd.GoToControl "CL_FORMAL_NAME"
End If
////////////////////////////////////////////////////////////////
Now, I get the message that the record is not saved if vbYes is selected but
I want the form to close at this point.
I should point out that that all fields with focus has a similar
beforeUpdate code and I am wondering if this is messing things up. I really
need the code attached to each field as not everyone will try to close the
form so reminders need to be in place for each required field as they tab
through the form.
Basically, what is happening is that on closing the form I get the vbYesNo
message box. If yes I am getting the not saved message but then the field
CL_FORMAL_NAME activates and the issues its message which I obviously don't
want to happen if the user is keen to exit set up.
Any suggestions
I have a form with required fileds which works great unleess someone want to
force close the form.
THis is part of the code which I am using
/////////////////////////////////////////////////////////////////////
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull([CL_KEY]) Then
Beep
MsgBox "The Client Key Is A Required Field - Please Enter The Correct
Client Key"
Cancel = True
DoCmd.GoToControl "CL_KEY"
Else
If IsNull([CL_FORMAL_NAME]) Then
Beep
response = MsgBox("The Formal Name Is A Required Field - Please
Enter The Correct Formal Name" & Chr(13) & "Do You Wish To Cancel Set Up?",
vbYesNo)
If response = vbYes Then
Cancel = True
Else
DoCmd.GoToControl "CL_FORMAL_NAME"
End If
////////////////////////////////////////////////////////////////
Now, I get the message that the record is not saved if vbYes is selected but
I want the form to close at this point.
I should point out that that all fields with focus has a similar
beforeUpdate code and I am wondering if this is messing things up. I really
need the code attached to each field as not everyone will try to close the
form so reminders need to be in place for each required field as they tab
through the form.
Basically, what is happening is that on closing the form I get the vbYesNo
message box. If yes I am getting the not saved message but then the field
CL_FORMAL_NAME activates and the issues its message which I obviously don't
want to happen if the user is keen to exit set up.
Any suggestions