Running code in a forms module

  • Thread starter Thread starter Demon
  • Start date Start date
D

Demon

I am using Access 97 and I want to open a form, insert parameters and then
run a public subroutine on the form to perform a search.

I can do all this except run the routine.
The code is behind a button on the search form:

Public Sub cmdSearch_Click()
.....
End sub

Thanks in advance,

Max
 
Treat your public routine like any other property of a form. (which are
public routines under the hood anyway)

Forms!MyMyform.MyPublicSub

or

SomeVar = Forms!MyMyform.MyPublicFunction
(for a public function)

hth
peter walker
 
There is no reason why you can't put your code in a public module.

Likely , the best approach is to "pass" the code the current instance of the
active form.

You can't use "me" in a public module, but you can pass the form name

So, the code behind the button can be

Public Sub cmdSearch_Click()

Call MySearch(me)

End sub

You now cut out all of hte ocde, and paste it into a sub in a stnadard
module


Public Sub MySearch(frm as form)

in place of

me.LastName, you wouold go

frm.LastName

or

frm.RecordSetClone

or whatever....

So, just replace the "me" with "frm" (you can even use a search and
replace).
 
Thanks very much.
It worked a treat.

Max

peter walker said:
Treat your public routine like any other property of a form. (which are
public routines under the hood anyway)

Forms!MyMyform.MyPublicSub

or

SomeVar = Forms!MyMyform.MyPublicFunction
(for a public function)

hth
peter walker
 
Back
Top