Set focus issue

M

Maracay

Hi Guys,

I have this routine to not let the users type more than 100 characters, the
problem is that after the message the focus is on the next field, I can’t
make it stay on ComboJobName even when I‘m using Me.ComboJobName.SetFocus,
there is any special reason for this to happen.

Thanks

Private Sub ComboJobName_LostFocus()
If Len(Me.ComboJobName) > 100 Then
MsgBox " Text is too long, maximun 100 characters, this is the text you
are allow to type: " & Me.ComboJobName
Me.ComboJobName.SetFocus
End If
End Sub
 
D

Dirk Goldgar

Maracay said:
Hi Guys,

I have this routine to not let the users type more than 100 characters,
the
problem is that after the message the focus is on the next field, I can’t
make it stay on ComboJobName even when I‘m using
Me.ComboJobName.SetFocus,
there is any special reason for this to happen.

Thanks

Private Sub ComboJobName_LostFocus()
If Len(Me.ComboJobName) > 100 Then
MsgBox " Text is too long, maximun 100 characters, this is the text you
are allow to type: " & Me.ComboJobName
Me.ComboJobName.SetFocus
End If
End Sub


The LostFocus event occurs *after* Access knows the focus is going to move
to another control, but *before* it has actually done so. For what you're
doing, use the combo box's BeforeUpdate event, and set the event procedure's
Cancel argument if it's necessary to keep the focus on the control.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top