By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,653 Members | 1,832 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,653 IT Pros & Developers. It's quick & easy.

cancel as integer and the like: why and how

P: n/a
Goodmorning Gurus

Here is another of my questions..... When adding code to a control then
access sometimes puts in a couple of 'parameters'. Can anyone tell me what
the use of them is. I have never used them, but I would be keen to do so.

Here is an example for a control (on a form) called CNW, when I add some
code for the BeforeUpdate event, access puts in the following lines.

Private Sub CNW_BeforeUpdate(******Cancel As Integer*******)

End Sub

Note: i put in the * for emphasis only

My questions are:

- why do some events have these extra "parameters"

- what is their use

- can I make my own ones like that? for example, on key down has some
very useful "parameters" that I could use for other functions.

TIA

- Nicolaas
---
Please immediately let us know (by phone or return email) if (a) this email
contains a virus
(b) you are not the intended recipient
(c) you consider this email to be spam.
We have done our utmost to make sure that
none of the above are applicable. THANK YOU
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.700 / Virus Database: 457 - Release Date: 06/06/2004
Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
The aguments either give you information, or allow you to tell Access how to
respond.

If the event procedure has a Cancel argument, then you can cancel the event
by setting that argument to True. Access fires the Form_BeforeUpdate event
when the record is about to be saved. You can block the save by setting
Cancel to True. This example stops the record from saving if the Surname
field is blank:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.Surname) Then
Cancel = True
Msgbox "You forgot to fill in the surname."
End If
End Sub

The KeyDown event has an argument named KeyCode. Access sets the value of
this argument to a number that lets you know which key was pressed. You can
then change the value to make it do something different. Changing the value
to zero destroys the keystroke. This example prevents the user from undoing
the control or record by pressing the Esc key, because it destroys that
keystroke:

Private Sub Form_KeyDown(KeyCode as Integer, Shift As Integer)
If KeyCode = 27 Then
KeyCode = 0
End If
End Sub
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"WindAndWaves" <ac****@ngaru.com> wrote in message
news:PK****************@news.xtra.co.nz...
Goodmorning Gurus

Here is another of my questions..... When adding code to a control then
access sometimes puts in a couple of 'parameters'. Can anyone tell me what the use of them is. I have never used them, but I would be keen to do so.

Here is an example for a control (on a form) called CNW, when I add some
code for the BeforeUpdate event, access puts in the following lines.

Private Sub CNW_BeforeUpdate(******Cancel As Integer*******)

End Sub

Note: i put in the * for emphasis only

My questions are:

- why do some events have these extra "parameters"

- what is their use

- can I make my own ones like that? for example, on key down has some
very useful "parameters" that I could use for other functions.

TIA

- Nicolaas
---
Please immediately let us know (by phone or return email) if (a) this email contains a virus
(b) you are not the intended recipient
(c) you consider this email to be spam.
We have done our utmost to make sure that
none of the above are applicable. THANK YOU
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.700 / Virus Database: 457 - Release Date: 06/06/2004

Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.