From: Maracay on
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

From: Dirk Goldgar on
"Maracay" <Maracay(a)discussions.microsoft.com> wrote in message
news:F3F0CCA2-5F9A-4AD5-87B7-4630F46D4DD3(a)microsoft.com...
> 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.

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)