Full Version: Problem with the focus
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
handsomed
I'd like to force the user to fill a column, so I have in the event "when lose the focus" the code to show a messagebox and the setfocus property to the column but it doesn't work. It shows the message but the focus is set to the column which a pointed to.
Any ideas?
theDBguy
Can you show us the code you're using?
handsomed
If IsNull(NAME) Then
MsgBox "You must write your name"
NAME.SetFocus
.......
theDBguy
Just curious... "NAME" is a reserved word in Access. Using it for field or control names can cause unexpected results. Could you try changing those names into something else, for example "FirstName", and see if that helps?
handsomed
Sorry, it was an example, I wrote NAME but I don't use it, my code would be:
If IsNull(FIRSTNAME) Then
MsgBox "You must write your name"
FIRSTNAME.SetFocus
Then when I click to another control, i get de message but not the focus to FIRSTNAME
theDBguy
Try this...
If IsNull(FIRSTNAME) Then
MsgBox "You must write your name"
Screen.PreviousControl.SetFocus
(untested)
Hope that helps...
handsomed
I didn't work theDBguy
theDBguy
Sorry about that, you might have to move the focus around a bit first to see if it helps...
If IsNull(FIRSTNAME) Then
MsgBox "You must write your name"
Me.SomeOtherControl.SetFocus
Me.FIRSTNAME.SetFocus
(untested)
Hope that helps...
handsomed
It worked theDBguy!
Curious way!
Thanks everyone
theDBguy
You're welcome. Glad we could help. Good luck with your project.
ote: If you are curious, it has to do with where the focus is at the moment the lost focus event fires.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.