Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Undo / Exit form

Status
Not open for further replies.

heidi88

Programmer
May 1, 2003
32
0
0
US
I have a form with two command buttons: Undo and Exit.

This form has several NOT NULL fields. When user leaves one of those fields blank and try to undo or exit the form, msg "Null value is not allowed" keep poping out and does not allow user to back out and start over again.

Anyone knows the VBA codes behind the Exit_Click() and Undo_Click() sub to completely ignore the constrains of and fields and just allow user to get out!

Thanks a lot!!!!

 
Heidi
From what you say, the table behind the form has several fields which are required. Which means that you cannot save a Null value in those fields (otherwise, there is no purpose in setting the field to required in the first place).

Therefore, I assume that you want to either Exit the form without saving the record when you press the Exit command button, or Undo the record and start re-entry when you press the Undo command button.

Here is an example of code that could be put behind your Undo button. This will undo the entire entry and reset the focus to the first field.
If IsNull(MyField) Or IsNull(MyField2) Then
MsgBox "This is a required Field. Please re-enter."
Me.Undo
Me.MyFirstFieldInForm.SetFocus
End If

There could be other variations of this. For example, if just one of the required fields is left blank, the focus would go to that field.
If IsNull(MyField2) Then
MsgBox "MyField2 is a required field."
Me.MyField2.SetFocus
End If

Hope this helps.

Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top