repetive coding

  • Thread starter Thread starter Jean-Paul De Winter
  • Start date Start date
J

Jean-Paul De Winter

Hi,

I created a from with a lot of listboxes.
Every time I change one, a procedure must run to check some things.
Of course I can type this procedure for every onclik procedure, but
this doesn't seem to be a good idea.
I would like to store the check-procedure in a different location and
every time I click the listbox, caal this code to execute it.
How can this be done.
Thanks
 
on 02/24/05 said:
I created a from with a lot of listboxes.
Every time I change one, a procedure must run to check some things. Of
course I can type this procedure for every onclik procedure, but this
doesn't seem to be a good idea.
I would like to store the check-procedure in a different location and
every time I click the listbox, caal this code to execute it. How can
this be done.

Database - Objects - Modules
Create a new module (this will be for VBA code only).
Put in it a Public Sub or Public Function.
That procedure can be called from any form or report.
 
Well I have done this for several forms. One of the ways I found useful was
to create either a module or form module then call that module from the click
event of the listbox.


aircode same form
Private Function UpdateForm()
dim whatever
do whatever

end Function

Then

Private Sub ListBx_Click()()
UpdateForm
dowhatever
end sub
 
You could define your Sub/Function in a seperate module, but if this code
fragment will only be used with this particular form, imo it would be better
to define your procedure in the Declarations section of the form itself.
When you define the procedure, it will automatically seperate from the
Declarations section.

You did not indicate that you need to know which List Box fired the Click
event, but you could pass the name of the control to the procedure so the
procedure knows which List Box its working with. I kind of know how to do
this, but not exactly. Perhaps someone who knows how can explain? I can see
myself needing this info in the near future.

Ozzone
 
OK thanks, but what is the code to actually "Call" the code to execute?
JP

It looks like you have got some reading to do if you want to
get into VBA programming. You can start with Visual Basic
Help - Function Statement, Call Statement and related topics. Study all
the examples. A book is necessary to really
understand what you are doing. Your local computer book
store can help you with that.
 
Back
Top