Set focus problem

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
 
D

Dan Artuso

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
 
T

Tony Williams

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
 
T

Tony Williams

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
 

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