Set focus problem

  • Thread starter Thread starter Tony Williams
  • Start date Start date
T

Tony Williams

PC Datasheet helped me with some code some days ago for which I'm very
grateful. I wanted a message to appear if the user didn't enter data into a
control on a form. Here is the code

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.txtMontha.SetFocus

Else
Me.Undo
End If
End If

The message appears just fine but I can't get the cursor to go back to the
control txtMontha it always goes to the next control on the form.
Can anyone help?
Thanks
Tony
 
Hi Tony,
It's always good to post what event your code is running from.
Try setting the focus to another control and then back to txtMontha
 
Thanks Dan worked just fine!!!
Tony
Dan Artuso said:
Hi Tony,
It's always good to post what event your code is running from.
Try setting the focus to another control and then back to txtMontha
 
Could anyone tell me how I could change the code so that if the user clicks
No the form closes. I've tried adding docmd.close instead of Me.Undo but VBA
wont let me do that it says that function isn't available '
Thanks
Tony
 
Back
Top