T
Tony Williams
I have a control on a form that has code which creates a message if the user
does not input any data. If I put this code in the OnLostFocus property of
the control it works fine, but if I put it in the BeforeUpdate property of
the form it doesn't. Here is the code:
Private Sub txtMontha_LostFocus()
Dim MsgStr As String
Dim TitleStr As String
MsgStr = "You can not enter a record without " _
& "completing the Qtr End Date" & vbCrLf & vbCrLf _
& "Do You Wish To Go Back " _
& "And Enter The Qtr End Date?"
TitleStr = "Qtr End Date Must Be Entered"
If IsNull(Me!txtMontha) Or Me!txtMontha = "" Then
If MsgBox(MsgStr, vbYesNo, TitleStr) = vbYes Then
Cancel = True
Me.txtMonthlabela.SetFocus
Me.txtMontha.SetFocus
Else
Me.Undo
End If
End If
End Sub
Two questions:
1. I would prefer it to go in the BeforeUpdate in the event that the user
uses a mouse rather than tabs around the form. Can anyone see where I can
change the code to make it work?
2. I would also like the form to close if the user answers No to the
message. I've tried using Docmd.Close but can't get the sequence right. The
form either closes when I don't want it to or wont close if the user has
input data and just wants to close the form when they've finished.
Thanks
Tony
does not input any data. If I put this code in the OnLostFocus property of
the control it works fine, but if I put it in the BeforeUpdate property of
the form it doesn't. Here is the code:
Private Sub txtMontha_LostFocus()
Dim MsgStr As String
Dim TitleStr As String
MsgStr = "You can not enter a record without " _
& "completing the Qtr End Date" & vbCrLf & vbCrLf _
& "Do You Wish To Go Back " _
& "And Enter The Qtr End Date?"
TitleStr = "Qtr End Date Must Be Entered"
If IsNull(Me!txtMontha) Or Me!txtMontha = "" Then
If MsgBox(MsgStr, vbYesNo, TitleStr) = vbYes Then
Cancel = True
Me.txtMonthlabela.SetFocus
Me.txtMontha.SetFocus
Else
Me.Undo
End If
End If
End Sub
Two questions:
1. I would prefer it to go in the BeforeUpdate in the event that the user
uses a mouse rather than tabs around the form. Can anyone see where I can
change the code to make it work?
2. I would also like the form to close if the user answers No to the
message. I've tried using Docmd.Close but can't get the sequence right. The
form either closes when I don't want it to or wont close if the user has
input data and just wants to close the form when they've finished.
Thanks
Tony