Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 1 / February 2006

Tip: Looking for answers? Try searching our database.

Wrong textbox gets focus.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
2D Rick - 16 Feb 2006 20:38 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)
<> 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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.