Where to put code for whole project?

andrefrancis

andrefrancis
Local time
Today, 11:47
Joined
Mar 11, 2005
Messages
40
I need to dimension variables and define string constants which will be relevant to all forms in a particular project.

Can someone tell me where I put these?

Thank you (in anticipation)
 
Putting them in a standard module would make them available across the project.

Code:
Public MyNumber as Long
Public Const MyString as String = "Hello World"

Regards,
Tim
 
pono1 said:
Putting them in a standard module would make them available across the project.

Code:
Public MyNumber as Long
Public Const MyString as String = "Hello World"

Regards,
Tim

I tried the above and it gave me a few problems. I suppose it all boils down to the fact that I don't really understand some of the Access terminology. What is a 'standard' module. I think I know what a project is (= a session using Access after double-clicking a .mdb thing) ... I also know what a procedure is, although Access confusingly calls them 'sub" in VBA. However, I don't know what to call the things in between (are they Form Objects?) which go with forms and contain the set of procedures (subs) for the form.

I have got this code in my main form 'on load':

Option Compare Database

Public mainpathstring As String

Private Sub Form_Load()
mainpathstring = "C:\Documents and Settings\andyf\My Documents\AFDoc_Laptop\"

However, at a later point in another form, when I need to access mainpathstring ... it is empty!

How do I keep the value of mainpathstring throughout the duration of the project session ... no matter which form I am using?
 
A module attached to a form or a report is a Class module and is enclosed. A standard module is one not attached to a form or a report and is not a Class Module. You add these from the Modules tab in the Database Window.
 
SJ McAbney said:
A module attached to a form or a report is a Class module and is enclosed. A standard module is one not attached to a form or a report and is not a Class Module. You add these from the Modules tab in the Database Window.

Thanks for replying so swiftly.

I will try setting my string constant as you suggest.
 
Also, above is not a constant.

This is a constant:

Code:
Public Const mainpathstring As String = "C:\Documents and Settings\andyf\My Documents\AFDoc_Laptop\"
 
I have now set up a module with a procedure as follows:

Sub pathset()
public mainpathstring as String
mainpathstring = "C:\ ....... etc"
End Sub

Do I need to run this on opening my project? ... and if so, how do I do that?
 
andrefrancis said:
I have now set up a module with a procedure as follows:

Sub pathset()
public mainpathstring as String
mainpathstring = "C:\ ....... etc"
End Sub

Do I need to run this on opening my project? ... and if so, how do I do that?

You don't need a procedure. Simply put the line I gave you above into a blank module and you can refer to mainpathstring from other places in your database.
 

Users who are viewing this thread

Back
Top Bottom