473,395 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Wrong textbox gets focus.

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

Feb 16 '06 #1
4 2158
>>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


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_ev...foreupdate.htm

HTH,
Mark
*****************@aol.com

Feb 16 '06 #2
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.

--
Wayne Morgan
MS Access MVP
"2D Rick" <rb*******@compuserve.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
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

Feb 16 '06 #3
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

Feb 17 '06 #4
That's fine. As long as the misspelling is consistent, Access doesn't know
the difference.

--
Wayne Morgan
MS Access MVP
"2D Rick" <rb*******@compuserve.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...

<< txtDiskSerialNumber (serial is misspelled) >>

Still working through issues from "Hooked on Phonics" and "New Math"
<g>

Thanks, Rick

Feb 17 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jonas L | last post by:
Hi, I need to create a textbox which acts as a normal textbox but with the following extra requirements: 1) In-focus color, when the textbox gets focus the backcolor property of the textbox...
0
by: Miquel | last post by:
Hi all. I felt frustrated when developing an 'UserControl' derivated from textBox, because sequence event (and Validate event) seems to fail. I Always thought my code was wrong. But after...
2
by: Jesper | last post by:
Hi, I'm showing a usercontrol containing a textbox on the screen by clicking a notifyIcon in the taskpane. I use textBox.Focus() to set the focus for the texbox, and I also get a blinking...
4
by: JC | last post by:
Hello- I have a form which has a listbox, a textbox and a submit button. The user types a phone number into the textbox, clicks button, text gets added to the listbox. After this process I need...
4
by: Tim Meagher | last post by:
I am finding some odd behavior. When clicking in a textbox, I find that the focus is resorting to a different button on my web page, not to the textbox.. I would like the focus to remain on the...
5
by: marfi95 | last post by:
I'm very confused. I'm trying to automatically select the text when my textbox gets the focus. This is typically when the user has clicked the mouse in the field. This is the code I have in...
2
by: Lenster | last post by:
Environment --------------- Visual Studio.NET 2003 Version 7.1.3088 ..NET Framework 1.1 Version 1.1.4322 SP1 XP Professional 5.1.2600 SP2 Build 2600 Problem Description...
4
by: slinky | last post by:
I have a textbox that a user enters the current time (in this case at the end of a task, and it gets its value via a button's click event and getting its value from =Now() ). Is there a way to...
10
by: engteng | last post by:
When textbox properties enable = False the font in the textbox become gray color. How do I change the gray color to black color ? Regards, Tee
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.