cancel event

krishnanhemanth

Registered User.
Local time
Today, 16:30
Joined
Jun 12, 2009
Messages
115
hi everybody
i have a form PURCHASE with a subform PURCHASE DETAILS.
in the subform there are the following fields
qty
tqd
status----- yes/no field

i have put the following code

Private Sub STATUS_GotFocus()
If Me.TQD = Me.QTY Then
Me.STATUS.Value = True
Else
Me.STATUS.Value = False
End If

End Sub

the problem is that in case the user misses to put focus on "status" then it is not updated..... so i put the below code

Private Sub Form_Close()
If Me.TQD = Me.QTY Then
If Me.STATUS.Value = False Then
MsgBox "SUPPLIED QTY HAS REACHED THE OREDER QTY"
End If
End If
End Sub

what i want is that if the above logic is true then
the form close event should cancel
the field "status" should get focus
the form can be closed only if the "status" field is updated

thanks in advance

hemanth
 
You need to use the form's BEFORE UPDATE event for validations and to cancel the update if something doesn't meet your conditions.

In the Before Update event you issue a

Cancel = True

to cancel the update

and a

Me.Undo

if you want to undo the fields that have been filled in.
 

Users who are viewing this thread

Back
Top Bottom