setting up a custom module

  • Thread starter Thread starter Gator
  • Start date Start date
G

Gator

how do I go about using code that will be used in serveral events on the same
form? For example, I'm going to change the background color of the form when
certain conditions exist. I want to check for the conditions either when
records are scrolled through or on changes on a current record. I've got the
code I need. I just need to know if there is a way to set the code up in one
place and call it in serveral events. Do I set up a custom standard module?
Class module? Can someone step me through this process?
 
Gator said:
how do I go about using code that will be used in serveral events on the same
form? For example, I'm going to change the background color of the form when
certain conditions exist. I want to check for the conditions either when
records are scrolled through or on changes on a current record. I've got the
code I need. I just need to know if there is a way to set the code up in one
place and call it in serveral events. Do I set up a custom standard module?
Class module?


You can use a standard module public function, but if the
function is only used in this one form, it would be cleaner
to put the function in the form's module.

Either way you can take advantage of a useful feature that
allows you to put =yourfunction(...) in the event
**property** to call your function.

If the function is in a standard module, then use:
=yourfunction(Form)
and code the function this way:

Public Function yourfunction(frm As Form)
If somecondition Then
frm.Section(0).BackColor = vbRed
Else
...

If the function is in the form's module, set the events'
property to
=yourfunction()
and code the function

Public Function yourfunction()
If somecondition Then
Me.Section(0).BackColor = vbRed
Else
...
 
Back
Top