Call sub from another form and pass parameters

CrArC

Registered User.
Local time
Today, 21:49
Joined
Oct 7, 2006
Messages
25
Hello there,
I'm trying to call a subroutine in one form from a sub in another, and passing it a simple integer in the process. Bit of a newb at this, if it was a sub from the same form then I could just write the name of the subroutine and it would be quite happy... i.e.:

[random code]
subname
[random code]

obviously it tells me it can't find the subroutine though as it's under a different object class (another form). I can't figure it out!

Here's the important bits with the rest chopped out:
Code:
Private Sub Invoice()
Dim BookingNo As Integer
BookingNo = Me!PackageID.Value
'The form that must be opened:
DoCmd.OpenForm "frmHandlingInvoices"  
'The code that must run a sub belonging to that form:
'... and pass BookingNo to that sub.
????

It's probably something really simple, but any help greatly appreciated 'cuz I can't suss it at all :)
 
It seems unnecessary to have two forms with two subroutines active at one time. I would try to condense the subroutine operations into one form.

You can pass values between OPEN forms. For example TEXTB in FORMB can get a value from TEXTA in FORMA using the following: TEXTB=FORMS![FORMA]![TEXTA]. By using this approach, you could pass all necessary values from FORMA to FORMB and then run your subroutine.

As an alternative, put your subroutine in the MODULES section of ACCESS and declare it as a PUBLIC subroutine. For example:
Code:
Public Sub Invoice (variable1 As integer, variable2 As Integer)
In theory, you should be able to pass variable1 and variable2 between your forms. This will also require that both forms be open at the same time. I have not experimented with this approach myself.
 
Ok cheers, it seems a lot simpler to stuff all the code into one form! I wanted it there in the other one in case the procedure would be useful for calling from another form. If this becomes neccessary I'll look into using modules :) thanks!
 

Users who are viewing this thread

Back
Top Bottom