We help IT Professionals succeed at work.

SetFocus, vbYesNo

pdvsa
pdvsa asked
on
Experts, not sure why the setfocus does not set the focus?
The name of the field is not the issue.  
I need to setfocus if I click Yes.
See any reason why?  Please see pic of error.
If I click Yes then I get the error.
If No then nothing happens which is correct.

I think it has something to do with not saving the field but not sure how to do that.
Thanks...

       If Not IsNull(Me!cboLCType) Then
             If MsgBox("Are you sure you want to change the LC Type?", vbYesNoCancel) <> vbYes Then
             Me.cboLCType.Undo
             'Me.Comments.SetFocus
             Cancel = True
            Else
       DoCmd.RunCommand acCmdSave
             Me.Comments.SetFocus
           
            End If
       
        End If YesNoError
Comment
Watch Question

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
What event (control or form) is this code in?

Is it in a Before Update event of a Control ?

mx
Database Architect / Application Developer
Top Expert 2007
Commented:
I guess it is because of Cancel=True.  If it's in the BU event of a Control, then you *cannot* set focus to another control in the BU event ...

mx
pdvsaProject finance

Author

Commented:
ahh yes I remember that.  It is in the BU event.  I forgot to copy that part.  thank you
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
Also, you cannot do a Save in a BU event, because a Save is what is *triggering* the BU event ... so you end up with an endless loop of sorts ...

mx