How to use the same subroutine in different forms?

  • Thread starter Thread starter Amit
  • Start date Start date
A

Amit

Hi,

This is probably quite easy, but I'm a newbie at VB and
will appreciate any help.

I have a subroutine for checking two dates on a form, and
I would like to call this subroutine from different forms
in the same project and database. How do I accomplish this?

Thanks!

-Amit
 
You can put the subroutine in a regular module (go to database window and
select modules). Declare it as a public subroutine and then you can call it
from anywhere within the project.

If the subroutine is using hard-coded references to controls on a form, then
you'll need to change the code to be generic and pass the specific control
references to the subroutine.
 
Hi Amit,

Insert a new module and code it something like the following:

Public Function DateCheck(Date1 as variant, Date2 as variant) as
Variant------This could be a string, whatever you want returned

DateCheck = --------- insert your routine here

End Function

Then from any place in your project you would use

NowDateCheck=DateCheck(Date1,Date2)---the Date1 and Date2 are the dates
you want to check

Karen
 
Hi Karen and Ken,

Thanks a lot for the prompt reply. Tried it, and it
worked!! Yay!! :)

Cheers,

-Amit
 
Back
Top