using modulename in code

You cannot reference a function in a different class module unless the form/report is actually open. If you want to use common code, put it in a standard module and define it as public and call it from multiple forms/reports. You can pass in a reference to the calling form so the code can reference form fields in the calling form by using frm.txtCustID. This of course requires that the names be consistent on all the forms that use this code. Just define the frm as below.

Public Sub MyProc( frm as Form)
 
You cannot reference a function in a different class module unless the form/report is actually open.
You are late to the game again, and really should read the whole thread because we beat this topic to death. As posted this would work, although as I pointed out a bad idea.
Code:
Form_Form1.myFunction()

That line of code opens an instance of the form hidden, and it goes out of scope once the procedure exits. So yes you can do it.

This demo would highlight
Code:
Private Sub Command1_Click()
  MsgBox "There are " & Forms.Count & " open"
  Form_Form1.HelloWorld
  MsgBox "There are " & Forms.Count & " Open"
End Sub

This procedure executed from form2 will run the method in form1 because this line instantiates an instance and runs the method.
Form_Form1.HelloWorld

Bottom line this can be done, but IMO should never be done unless you full understand. You are opening an instance of a form with all the overhead.
 
You are late to the game again, and really should read the whole thread because we beat this topic to death. As posted this would work, although as I pointed out a bad idea.
You might try reading my entire response before being rude.

1. The form MUST BE OPEN for you to reference any code.
2. Who knows what will happen if the code references the Me. object?

We do agree that it is poor practice.
 

Users who are viewing this thread

Back
Top Bottom