set focus after message box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form with a combo box containing numbers up to 9 in .25 increments.
I'd like to display a message box if the user tries to manually enter
something greater than 9. Then I'd like to set the focus on the combo box.
The message box code works, but the set focus code does not. I've tried the
code in the afterupdate and onexit subs. The code is below. What am I doing
wrong?

Private Sub Hours_AfterUpdate()

If Hours.Value > 9 Then
MsgBox ("Please select an option from the drop-down menu." _
& vbCrLf & "If an option is not available, ask yourself why you
work so much.")
Me.Controls(Hours).SetFocus
End If

End Sub
 
Hi Melanie,

I had the same issue a few weeks back, and someone in the forum suggested
that I add the statement:

Cancel=True

before the me.controls.SetFocus line. That worked for me!
 
instead of using the AfterUpdate event, suggest you use the NotInList event,
as

Private Sub Hours_NotInList(NewData As String, Response As Integer)

MsgBox "Please select an option from the drop-down menu." _
& vbCr & "If an option is not available, ask yourself why " _
& "you work so much."
Me!Hours = Null
Response = acDataErrContinue

End Sub

make sure the combo box's LimitToList property is set to Yes.

hth
 
Back
Top