Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

canceling an on open event

Status
Not open for further replies.

jeffmoore

Programmer
Aug 29, 2003
301
US
Why is this not working????
When I trace thru this code all 4 line are executed but the open event is not canceled....

Private Sub Form_Open(Cancel As Integer)
If Me.Recordset.RecordCount = 0 Then
Cancel = True
DoCmd.CancelEvent
End If
:
other code
:

end sub


TIA
Jeff
 
From here

The CancelEvent action method cancels the event that caused Microsoft Access to run the code containing this action
Docmd.CancelEvent

Remarks
This method has no arguments and can be called directly using the syntax DoCmd.CancelEvent.

The CancelEvent method has an effect only when it's run as the result of an event. This method cancels the event.

All events that can be canceled in Visual Basic have a Cancel argument. You can use this argument instead of the CancelEvent method to cancel the event. The KeyPress event and MouseDown event (for right-clicking only) can be canceled only in macros, not event procedures, so you must use the CancelEvent action in a macro to cancel these events.
 
Still why does the code not quit running at the first docmd.cancelevent command or when cancel = -1 ????

this is how I worked around the prob.

Private Sub Form_Open(Cancel As Integer)
If Me.Recordset.RecordCount = 0 Then
Cancel = True
DoCmd.CancelEvent
exit sub <---- this line added
End If
:
other code
:

end sub

Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top