This code does not return focus to Me.txtDiskSerailNumber, it moves it
to the next textbox in the tab order. How can I force it to setfocus
where I want it.
Private Sub txtDiskSerailNumber_AfterUpdate()
If Len(Me.txtDiskSerailNumber) <> 8 And Len(Me.txtDiskSerailNumber)
<> 12 Then
MsgBox "Bad Serial Number ""Length""", vbCritical, "Input
Error"
Me.txtDiskSerailNumber.SetFocus
Exit Sub
End If
End Sub
Thanks, Rick
accesspro4u@aol.com - 16 Feb 2006 22:03 GMT
>>This code does not return focus to Me.txtDiskSerailNumber, it moves it
>>to the next textbox in the tab order. How can I force it to setfocus
>>where I want it.
>> Private Sub txtDiskSerailNumber_AfterUpdate()
>> If Len(Me.txtDiskSerailNumber) <> 8 And Len(Me.txtDiskSerailNumber)
[quoted text clipped - 5 lines]
>> End If
>> End Sub
>> Thanks, Rick
It may be helpful to move your validation code to the BeforeUpdate
event.
Then you can 'Cancel' the update if the data is invalid. This will
keep the
focus in that text field, so the user can re-enter data.
For an example see:
http://www.blueclaw-db.com/access_event_programming/beforeupdate.htm
HTH,
Mark
***accesspro4u***@aol.com
Wayne Morgan - 16 Feb 2006 23:42 GMT
Mark is correct, do the validation in the BeforeUpdate event. The problem
isn't that the code isn't moving the focus to txtDiskSerialNumber (serial is
misspelled), it's that it is doing this before Access moves the focus
because you tabbed out of the control, so the tab to the next control is
still taking effect, but after the code runs. Issuing the Cancel in the
BeforeUpdate if the validation fails will solve this problem. You won't need
the SetFocus statement.

Signature
Wayne Morgan
MS Access MVP
> This code does not return focus to Me.txtDiskSerailNumber, it moves it
> to the next textbox in the tab order. How can I force it to setfocus
[quoted text clipped - 11 lines]
>
> Thanks, Rick
2D Rick - 17 Feb 2006 13:04 GMT
Thanks for the two replies to my message.
All works perfect now.
<< txtDiskSerialNumber (serial is misspelled) >>
Still working through issues from "Hooked on Phonics" and "New Math"
<g>
Thanks, Rick
Wayne Morgan - 17 Feb 2006 17:13 GMT
That's fine. As long as the misspelling is consistent, Access doesn't know
the difference.

Signature
Wayne Morgan
MS Access MVP
> << txtDiskSerialNumber (serial is misspelled) >>
>
> Still working through issues from "Hooked on Phonics" and "New Math"
> <g>
>
> Thanks, Rick