We help IT Professionals succeed at work.

AfterUpdate, setfocus

pdvsa
pdvsa asked
on
Experts, why do I get a "define variable" on the cancel=True?

I moved the code to the AU from the BU.  
In the BU I did not get such an errror.

Private Sub cboLCType_AfterUpdate()

           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
       
End Sub
Comment
Watch Question

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

Commented:
Because the AU event does not have a Cancel argument like the BU event ... so you cannot use it.

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

Commented:
Try using the Form BU event, which has a Cancel argument ... AND ... you can SetFocus to another control - as part of your validation routine ...

mx
Database Architect / Application Developer
Top Expert 2007
Commented:
But you still need to remove then  DoCmd.RunCommand acCmdSave  code, because Save triggers a BU event.
Maybe ... something like this ... note what I've commented out ...

Private Sub Form_BeforeUpdate (Cancel As Integer)

           If Not IsNull(Me!cboLCType) Then
             If MsgBox("Are you sure you want to change the LC Type?", vbYesNoCancel) <> vbYes Then
             'Me.cboLCType.Undo ' no can do here
             'Me.Comments.SetFocus  ?
             Cancel = True
            Else
             ' DoCmd.RunCommand acCmdSave ' no can do here
             Me.Comments.SetFocus
           
            End If
       
        End If
       
End Su
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
End Su >>> End Sub
pdvsaProject finance

Author

Commented:
OK I will checkk that out.  

thank you...gotta run to one of those corporate meetings again.  geez...
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
you are welcome ...

mx