setfocus method

iommi

New member
Local time
Today, 13:52
Joined
Mar 10, 2000
Messages
6
Hello again.

Sorry to disturb again, but i forgot to ask one thing in my question below.

If I put some validation code in the afterupdate or onexit event in a textbox, runs the validation (something is not to be less than 3) via the form (The user types some value which my validation discovers) and I want to first display a msgbox "Wrong value - lower than 3" and the run the [txtbox].setfocus method on the txtbox ...how to do it?

The txtbox just wont get focus; The control AFTER the txtbox will always get the focus!

To put it in other words, I want to loop and loop on the samt txtbox, until the user finally gets it right; puts something > 3. Only after this, is the control after my txtbox aloud to get its focus.

How?

the code:

sub validate()
if [txtbox] < 3 then
msgbox "No, no..."
[txtbox].setfocus 'Wont just work!!
end if
end sub
 
I'm not sure if this is a glitch in Access, but I've had the same problem with various other codes using SetFocus. I've gotten around it by using SetFocus on another control first, then going to the control I want:

[any other control].SetFocus
[txtbox].setfocus

Maybe someone else has a better solution, but this does work.
 
Can you not use the Before Update event to validate your entry instead of the After Update event? You have the abilty to cancel, and the focus remains in the current txtbox.

Just a thought,
RDH
 
No. I tried this after readíng your advice...
but I cannot validate in the beforeupdateevent. Access complains about this. It says its values must be saved before the code in the beforeupdateevent occours (in my case the validation).
So its back to the origin problem. But I followed the advice to have another control to escape to on the afterupdate event...and if myvar = 1 then return to the [firstcontrol].

Not a sexy solution, but it works.

Many thanks for your advice.
 
Why don't you add a CancelEvent command on the OnExit event if the validation fails. This won't allow the focus to change until the value is acceptable
 
Hi,
It looks like, in Access 2000, we must now do data validation on the exit event instead of the after update event, which is the way we did it in Access 97.

Mike
 

Users who are viewing this thread

Back
Top Bottom