[Event Procedure] Code Behind Form

H

Howard

I have procedures behind a Access forms. I created a event procedure from
the form's properties windows or sometimes I copy code from another form's
code and paste that code behind another form. I then modify that codes as
needed and then compile the code which I believe creates the [Event
Procedure] text for each event that may be called from the event procedures
found in the pasted code.

(1) From time to time a form's [Event Procedure] property text in the
form's property window comes up missing -- gone, disappears.

(2) And, in a particular Access database, the entire code behind the form
sometimes comes up missing. I've then have to get an archived copy of the
code, paste it into the form's code module, compile the code, test the
functionality of the command buttons that work okay now. And this form will
be good for a while or days, but then I will have another experience where
the code becomes missing again. No way has there ever been a property
setting of HasModule = False that would have removed the code. However, the
behavior of this one application is acting like it has been invoked.

What is happening here in these two incidents? Is this possibly a side
effect of a database corruption that I experience from time to time after
adding code behind forms, etc?

I am using:

Microsoft Access 2003 SP3
The original form and code in (2) above was designed in an Access 97
database, but imported, modified and deployed in many projects in
Access 2000, Access 2002, and Access 2003
Database developed on a Windows XP and then moved to Windows Vista Ultimate
which now with SP1
Database deployed on Windows XP and a few Vista computerfs

Is there are good code snippet that I could use to check programmatically
code events like _Click, _AfterUpdte, etc and verify if the code has a
corresponding [Event Procedure] property? Does any one have or use code like
this that they are willing to share? If not, I will start the process of
writing a code procedure to check this.

Howard
 
A

Allen Browne

Hi Howard

This does happen sometimes, and there may be several possible causes.

Example of #1: Sometimes you cut a control from a form, and then paste it
back in (e.g. to move it from sitting directly on the form, into the page of
a tab control.) When you do that, the code becomes disconnected, and you
have to set its event properties again to connect the code to the control.

Example of #2: Access keeps 2 copies of the code: the Text version (what you
read and edit), and the binary version (what actually executes.) The binary
is different for every version of Access. Newer versions can use the binary
of older versions, but not the reverse. When you switch an MDB back to an
older version, it automatically recompiles the binary from the text. When
you come forward a version, as soon as you make any change, the binary is
updated to the new version. This process is not perfect: the database
gradually bloats with spurious binary that doesn't get removed, and weird
effects can creep in (such as the code breaks at a breakpoint that does not
exist in the text version of the code, or doesn't break at a breakpoint that
does exist in the text version.) This kind of corruption is fixed with a
decompile (which instructs Access to dump the entire binary, so it can
re-create it again from the text.)

For suggestions on avoiding this kind of corruption, see:
Preventing Corruption
at:
http://allenbrowne.com/ser-25.html

I'm not aware of a utility that identifies procedures that match an object +
event name, where the appropriate event property is not set. Sounds doable
through.

A fairly simple fix is to cut all the code from a module, and paste it back
in. You should see all the right event properties set when you do that.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Howard said:
I have procedures behind a Access forms. I created a event procedure from
the form's properties windows or sometimes I copy code from another form's
code and paste that code behind another form. I then modify that codes as
needed and then compile the code which I believe creates the [Event
Procedure] text for each event that may be called from the event procedures
found in the pasted code.

(1) From time to time a form's [Event Procedure] property text in the
form's property window comes up missing -- gone, disappears.

(2) And, in a particular Access database, the entire code behind the form
sometimes comes up missing. I've then have to get an archived copy of the
code, paste it into the form's code module, compile the code, test the
functionality of the command buttons that work okay now. And this form
will be good for a while or days, but then I will have another experience
where the code becomes missing again. No way has there ever been a
property setting of HasModule = False that would have removed the code.
However, the behavior of this one application is acting like it has been
invoked.

What is happening here in these two incidents? Is this possibly a side
effect of a database corruption that I experience from time to time after
adding code behind forms, etc?

I am using:

Microsoft Access 2003 SP3
The original form and code in (2) above was designed in an Access 97
database, but imported, modified and deployed in many projects in
Access 2000, Access 2002, and Access 2003
Database developed on a Windows XP and then moved to Windows Vista
Ultimate which now with SP1
Database deployed on Windows XP and a few Vista computerfs

Is there are good code snippet that I could use to check programmatically
code events like _Click, _AfterUpdte, etc and verify if the code has a
corresponding [Event Procedure] property? Does any one have or use code
like this that they are willing to share? If not, I will start the
process of writing a code procedure to check this.
 
S

Stuart McCall

A fairly simple fix is to cut all the code from a module, and paste it
back in. You should see all the right event properties set when you do
that.
<SNIP>

Good tip Allen. Thanks.
 
H

Howard Walters

Thanks, Allen.

I had a feeling when I wrote my post that I would be getting an excellent
answer from "down under".

Thanks again.

Howard

Allen Browne said:
Hi Howard

This does happen sometimes, and there may be several possible causes.

Example of #1: Sometimes you cut a control from a form, and then paste it
back in (e.g. to move it from sitting directly on the form, into the page of
a tab control.) When you do that, the code becomes disconnected, and you
have to set its event properties again to connect the code to the control.

Example of #2: Access keeps 2 copies of the code: the Text version (what you
read and edit), and the binary version (what actually executes.) The binary
is different for every version of Access. Newer versions can use the binary
of older versions, but not the reverse. When you switch an MDB back to an
older version, it automatically recompiles the binary from the text. When
you come forward a version, as soon as you make any change, the binary is
updated to the new version. This process is not perfect: the database
gradually bloats with spurious binary that doesn't get removed, and weird
effects can creep in (such as the code breaks at a breakpoint that does not
exist in the text version of the code, or doesn't break at a breakpoint that
does exist in the text version.) This kind of corruption is fixed with a
decompile (which instructs Access to dump the entire binary, so it can
re-create it again from the text.)

For suggestions on avoiding this kind of corruption, see:
Preventing Corruption
at:
http://allenbrowne.com/ser-25.html

I'm not aware of a utility that identifies procedures that match an object +
event name, where the appropriate event property is not set. Sounds doable
through.

A fairly simple fix is to cut all the code from a module, and paste it back
in. You should see all the right event properties set when you do that.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Howard said:
I have procedures behind a Access forms. I created a event procedure from
the form's properties windows or sometimes I copy code from another form's
code and paste that code behind another form. I then modify that codes as
needed and then compile the code which I believe creates the [Event
Procedure] text for each event that may be called from the event procedures
found in the pasted code.

(1) From time to time a form's [Event Procedure] property text in the
form's property window comes up missing -- gone, disappears.

(2) And, in a particular Access database, the entire code behind the form
sometimes comes up missing. I've then have to get an archived copy of the
code, paste it into the form's code module, compile the code, test the
functionality of the command buttons that work okay now. And this form
will be good for a while or days, but then I will have another experience
where the code becomes missing again. No way has there ever been a
property setting of HasModule = False that would have removed the code.
However, the behavior of this one application is acting like it has been
invoked.

What is happening here in these two incidents? Is this possibly a side
effect of a database corruption that I experience from time to time after
adding code behind forms, etc?

I am using:

Microsoft Access 2003 SP3
The original form and code in (2) above was designed in an Access 97
database, but imported, modified and deployed in many projects in
Access 2000, Access 2002, and Access 2003
Database developed on a Windows XP and then moved to Windows Vista
Ultimate which now with SP1
Database deployed on Windows XP and a few Vista computerfs

Is there are good code snippet that I could use to check programmatically
code events like _Click, _AfterUpdte, etc and verify if the code has a
corresponding [Event Procedure] property? Does any one have or use code
like this that they are willing to share? If not, I will start the
process of writing a code procedure to check this.
 

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

Top