Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 535
  • Last Modified:

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
0
Frank Freese
Asked:
Frank Freese
3 Solutions
 
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
 
Rey Obrero (Capricorn1)Commented:
btw, did you removed  Me.YearID.SetFocus from the beforeupdate event ?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now