Before Update Event Question

R

Renee

Good Morning All,

I have some validation on the before update event of a form. When I
click the close button, the form's Before Update event is firing perfectly
except for one thing. If the update event is canceled, I also want to cancel
the close command. Any suggestions?

Thanks!
Renee
 
G

Gijs Beukenoot

Renee heeft uiteengezet op 31-8-2005 :
Good Morning All,

I have some validation on the before update event of a form. When I
click the close button, the form's Before Update event is firing perfectly
except for one thing. If the update event is canceled, I also want to cancel
the close command. Any suggestions?

Thanks!
Renee

You can set Cancel to True in the unload-event of the form. However,
that means your validation(s) must set a boolean to determine if any
validation fails.

Private m_bCancel as boolean

in the form unload
if m_bcancel then
cancel = true
msgbox "Can't close now due to validation errors"
endif

in the validate function, start with
m_bcancel = false
and then, right before setting the cancel to true (due to failing the
validation), set it to true
m_bCancel = true
 
R

Renee

I am not sure what I have done wrong. The before update event is still firing
but the unload event is not. Is it because my form's before update is a
Private Sub?

From the Form's Before Update Event:
Private Sub Form_BeforeUpdate(cancel As Integer)
Dim m_bCancel As Boolean
m_bCancel = False

If IsNull(Me.Plan_Year) And Me.Apply = True Then
MsgBox "Enter the plan year.", vbInformation, "Reminder"
Me.Plan_Year.SetFocus
m_bCancel = True
cancel = True
End If
End Sub

From the form's Unload Event:
Private Sub Form_Unload(cancel As Integer)
If m_bCancel = True Then
cancel = True
MsgBox "Can't close now due to validation errors"
End If

End Sub

Thank you for your help Gijs,
Renee
 
Top