Are there functions/Or Events that are called automatically whenthe database file first opens and Wh

C

CES

All,
I'm assuming its "Public Function init_something()" but I can't seem to find a reference to the correct syntax. I'm using Access 2007.

Basically what I'm trying to do is initialize a list of global variables and I can't seem to figure out how to do it.

Option Compare Database

Public VariableName As String

'Call Init - Will throw an error
'VariableName = "Hello World" - Will throw an error

Option Explicit

Public Function Init()
VariableName = "Hello World"
End Function

Private Sub btName_Click()
MsgBox (VariableName)
End Sub

' this is the only way that I can seem to get this to work and I'm sure that there is a better way of doing it.

Private Sub test_Click()

If VariableName = "" Then
Call Init
End If

MsgBox (VariableName)
VariableName = "Some New Value"
End Sub

Also are all modules initiated when the database first opens?
Is there an order to when they are loaded?

Thanks in advance. - CES
 
P

Powderfinger

All macros named AutoExec.


CES said:
All,
I'm assuming its "Public Function init_something()" but I can't seem to
find a reference to the correct syntax. I'm using Access 2007.
Basically what I'm trying to do is initialize a list of global variables
and I can't seem to figure out how to do it.
Option Compare Database

Public VariableName As String

'Call Init - Will throw an error
'VariableName = "Hello World" - Will throw an error

Option Explicit

Public Function Init()
VariableName = "Hello World"
End Function

Private Sub btName_Click()
MsgBox (VariableName)
End Sub

' this is the only way that I can seem to get this to work and I'm sure
that there is a better way of doing it.
 
J

John W. Vinson

Also are all modules initiated when the database first opens?

No: only when a Sub or Function in the module is called. The modules just sit
there waiting to serve.

I'd suggest having a Form open automatically - use Tools... Startup and select
a form name. You can do your initialization code in that form's Open event.
Disable its Close button but provide a button to make it invisible so the user
doesn't inappropriately close and reopen it.

John W. Vinson [MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top