Full Version: Cancel Subform Update And Move Focus To Parent Control
UtterAccess Forums > Microsoft® Access > Access Forms
RexRivers
I'm setting up a form for company info and have a subform with preset options for that particular company.
I have a combobox with options to send confirmations to the company after a particular operation is completed.
If the user chooses "Email" confirmation I'd like the subform to check if an email has been provided on the parent form.
If one has not been provided I'd like to move the focus to the email textbox on the parent form.
I'm currently getting a RT error 2110 stating that it can't move the focus to 'HospEmail'
Any help would be appreciated.
CODE
Private Sub cboSpellCheck_BeforeUpdate(Cancel As Integer)
Select Case Me.cboSpellCheck
Case 1 ' Email
If Nz(Me.Parent!HospEmail, "") = "" Then
MsgBox "You cannot set Spell Check to Email if an Email is not provided." & _
vbCrLf & vbCrLf & "Please enter an email address first.", vbInformation, "NO EMAIL PROVIDED"
Cancel = -1
Forms!frmHospitalsInfo!HospEmail.SetFocus
End If
Case 2 ' Fax
'
Case 3 ' None
'
End Select
End Sub
J.D.
The problem is you are only canceling the change to the combo box and the record is still in edit mode and so won't allow you to move the focus to the main form.
If you want to cancel all changes to the subform you can use me.undo instead of cancel= true. I'd also change the setfocus call. so your code might look something like this...
CODE
Private Sub cboSpellCheck_BeforeUpdate(Cancel As Integer)    
Select Case Me.cboSpellCheck        
   Case 1 ' Email
            If Nz(Me.Parent!HospEmail, "") = "" Then                
                MsgBox "You cannot set Spell Check to Email if an Email is not provided." & _
                   vbCrLf & vbCrLf & "Please enter an email address first.", vbInformation, "NO EMAIL PROVIDED"
                  Me.undo                
                  Me.Parent.Form.HospEmail.SetFocus
            End If
   Case 2 ' Fax
     '
   Case 3 '
       None
            '
End Select
End Sub

If that is undoing too much we can use in place of me.undo
Cancel = true
me.dirty = false
That may generate other errors though without knowing more about the forms, data, coding etc.
hope this helps,
RexRivers
Perfect! Thank you!
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.