Cancel as integer

  • Thread starter Thread starter Stapes
  • Start date Start date
S

Stapes

Hi

The system I am working on has loads of procedures triggered by a
double-click. I have been asked to change it to a single click.
Simple solution. I created the 'Event Procedure', and then used Call
procedure_dblClick(cancel).
All the existing procedures have 'cancel as integer'. I tried adding
this to my procedures & the compiler won't have it, so I have had to
put 'dim cancel as integer' in my procedures. Why is this?

Stapes
 
Call procedure_dblClick(False)

Cancel is the name of the argument, not its value. You want to set the
cancel value to False because you don't want to cancel the procedure.
 
Call procedure_dblClick(False)

Cancel is the name of the argument, not its value. You want to set the
cancel value to False because you don't want to cancel the procedure.








- Show quoted text -

Hi
You missed my point - why can I not put Cancel as integer on my own
Function/Subroutine definitions.
Stapes
 
You can't add your own arguments to procedures associated with events. Some
event procedures take arguments and some don't. You can't change that. You
can create your own events that take arguments:

Public Sub as MyProc(Cancel as integer)
if Cancel = true then
exit sub
end if
End Sub

Then to call it:
Call MyProc(False)

So, in the declaration for your sub or function, you assign names and data
types to your arguments. You can also specify whether they are optional and
whether they are passed by value or reference. Then in the call statement,
you supply a value.

PS, I avoid using names that already have a meaning to Access (such as
Cancel) since they have a tendency to cause confusion.
 
Stapes said:
You missed my point - why can I not put Cancel
as integer on my own Function/Subroutine definitions.

You certainly can; it will be just another argument passed to or from your
Sub or Function. Then you can include code in your procedure, or in the
calling code if that is appropriate, to do something with the argument. But
Access will not do anything with a Cancel argument that you provide.

Access only responds to the Cancel argument for those certain event
procedures for which Access supplies it in the Sub or Function statements.
The Cancel arguments automatically included are set within the procedure to
cancel the event (e.g., in the BeforeUpdate event, setting Cancel = True
before exiting will cancel the Update). That is, the calling code is Access
itself, and that's where those Cancel arguments are handled.

Larry Linson
Microsoft Access MVP
 
Stapes said:
You missed my point - why can I not put Cancel
as integer on my own Function/Subroutine definitions.

Sorry, I re-read this and believe you mean you wanted to add a Cancel
argument to the Click event procedure. In their wisdom, the designers did
not include the ability to Cancel a Click event, though they did allow
Cancelling a Double-Click. We could speculate that the reason has something
to do with it being possible to have both Click and Double-Click events for
the same object, but that would only be speculation -- I just assume that
they had good reasons for the design decision (which may be an overly
optimistic view).

Is the Cancel argument set within any of the Double-Click event procedures?
I'm not sure what the effect would be of Cancelling in Double-Click... it's
not the event _procedure_ that is Cancelled when Access processes that
argument, but the event itself ... that is, in BeforeUpdate, returning
Cancel causes the Update itself to not take place.

Larry Linson
Microsoft Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top