Run-time error 2108

Experts,
I have this code in the BeforeUpdate event of a combo box:
Private Sub MonthID_BeforeUpdate(Cancel As Integer)
Beep
UserResponse = MsgBox("Is " & MonthID.Column(1) & " the correct month?", vbYesNo, "Correct Month")
If UserResponse = vbNo Then
    Cancel = True
    Me.MonthID.Undo
    Exit Sub
 Else
 Me.YearID.SetFocus
End If
End Sub

Open in new window

I get this error:
You must save the field before you execute the SetFocus method.
So I put this code in the AfterUpdate event
Me.YearID.SetFocus

Open in new window

And got the same error.
My objective is that if everything is OK move the focus to the next control, YearID
Frank FreeseAsked:
Who is Participating?
 
Rey Obrero (Capricorn1)Commented:
btw, did you removed  Me.YearID.SetFocus from the beforeupdate event ?
0
 
mbizupCommented:
I could be reading that wrong, but I'd think that unconditionally forcing the focus like that could create a frustrating user experience.

How about simply setting that control next in the tab order?
0
 
Rey Obrero (Capricorn1)Commented:
So I put this code in the AfterUpdate event

Me.YearID.SetFocus


that should work...


do a compact and repair of the db.

do a debug >compile, correct all errors raised..
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Jeffrey CoachmanMIS LiasonCommented:
FWIW, this code worked fine for me.

Private Sub txtMonthID_BeforeUpdate(Cancel As Integer)
'Declare the variable
Dim bytUserResponse As Byte
Beep
bytUserResponse = MsgBox("Is " & txtMonthID & " the correct month?", vbYesNo, "Correct Month")
    If bytUserResponse = vbNo Then
        Me.txtMonthID.Undo
        Cancel = True
        Exit Sub
    Else
        'No real need to do this,
        'because if Yes, then the focus will move to the next control in the tab order anyway...
        'Me.YearID.SetFocus
    End If

End Sub


Sample attached

JeffCoachman

Database79.mdb
0
 
Frank FreeseAuthor Commented:
woops....thanks capricorn. removed the beforedate code.
0
 
Frank FreeseAuthor Commented:
thanks to all
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.