setting focus after error

M

mharness

Hello,

Seems like I've been having trouble with this for a while and I don't know
why I feel the need for a solution today but here's the problem.

What do I need to do to put the focus back on a field where I have just
triggered an event. Something like this:

Dim strPrompt As String
If Me.SpotsCount < 1 Or Me.SpotsCount > 1000 Then
strPrompt = "Spots Count must be between 1 and 1,000."
MsgBox strPrompt, vbOKOnly, "Bad Number"
Me.SpotsCount.SetFocus
Me.SpotsCount = Null
End If

The problem is that the cursor always ends up in the next field in the tab
order and what I want is for it to be in the field where the error occured
so the user can correct it.

I know I can control this by removing the tab stops and setting the focus
programatically from one field to another but I'd rather not.

Thanks,

Mike
 
M

mharness

Hello Roy,

Thank you for the suggestions. I set the focus to another field and then
back to the one I actually wanted and got the action I want--the focus is on
the field where the error occured and it is now blank.

Many thanks,

Mike
 
R

RoyVidar

mharness wrote in message said:
Hello,

Seems like I've been having trouble with this for a while and I don't know
why I feel the need for a solution today but here's the problem.

What do I need to do to put the focus back on a field where I have just
triggered an event. Something like this:

Dim strPrompt As String
If Me.SpotsCount < 1 Or Me.SpotsCount > 1000 Then
strPrompt = "Spots Count must be between 1 and 1,000."
MsgBox strPrompt, vbOKOnly, "Bad Number"
Me.SpotsCount.SetFocus
Me.SpotsCount = Null
End If

The problem is that the cursor always ends up in the next field in the tab
order and what I want is for it to be in the field where the error occured so
the user can correct it.

I know I can control this by removing the tab stops and setting the focus
programatically from one field to another but I'd rather not.

Thanks,

Mike


My guess is that you're using a wrong eveng. I'd try using the
controls before update event, then just issue a

cancel = true

when the control fails validation. To continue using the event you're
using, you might try the "dirty" version of just setting focus to
another control first

Me!txtSomeOtherControl.setfocus
Me!SpotsCount.SetFocus
 
Top