Link to home
Start Free TrialLog in
Avatar of jondecker76
jondecker76

asked on

Is it possible to import an Module's namespace into a form's code? (So I don't have to type module1.this() for example)

I'm starting to use a lot of functions in modules. I find that it would be nice to somehow "include" a module into a form, so that its functions can be accessed without having to type module1. before every function I need to use.
I know its possible, just not how to do it, and searching didn't get me too far as I'm unsure of the terminology.

thanks
Avatar of LennyGray
LennyGray
Flag of United States of America image

All you have to do is declare the sub or function as Public and it will be available to all forms and queries.

Public MyFunctionName(sSomeParameter as string) as String

or

Public MyFunctionName() as String

or

Public Sub MySubName()

The same applies to application-wide variables. You can create a Globals module with global variables. Below is an example of a Globals module:
Option Compare Database
Option Explicit
 
 
'********************
'* System Constants *
'********************
   
    Public Const sTitle As String = "Sales Inquiry Application" ' sMsgbox title.
 
'******************
'*   DEFINITIONS  *
'******************
 
    '********************
    '* sMsgBox - related *
    '********************
    Public sMsg As String
    Public iDgDef As Integer
    Public iUserResponse As Integer     ' Evaluated by vbYes, vbNo, etc.
    
    '******************
    '* Form - related *
    '******************
    Public bCloseFormFlag As Boolean    ' True will let the form close, False will block the closure
    Public sDataEntryMode As String     ' "ADD", "CHANGE", "DELETE"
    Public bIsFormDirty As Boolean
    Public sFormCaption As String
    Public sControlFileFormName As String
    Public sControlFileHeading As String
    
    '********************
    '* System Variables *
    '********************
    Public i As Long                    ' counter
    Public sReportTitle As String       ' for e-mailed reports
    Public sVersion As String
    

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of LennyGray
LennyGray
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jondecker76
jondecker76

ASKER

Thanks - I would have never guessed this