currentproject.path as a global variable

G

Guest

Hi all,

I am trying to declare a global variable in my module that stores the value of path of my database with the following codes

Global Const currDir As String = CurrentProject.Path

when i tried to access the variable, currDir in my Sub procedure, my program does not run.

Please advise what's wrong with my declaration.

Thanks & regards
yann
 
M

Marshall Barton

yann said:
I am trying to declare a global variable in my module that stores the value of path of my database with the following codes

Global Const currDir As String = CurrentProject.Path

when i tried to access the variable, currDir in my Sub procedure, my program does not run.

Please advise what's wrong with my declaration.

The Const statement does not accept functions, methods, etc,
it only knows how to interpret expression that use literal
calues and other constants.

You could change that to a string variable:

Public currDir As String

and then assign its value in your startup form:

currDir = CurrentProject.Path
 
G

Guest

Thank you Marshall for your prompt reply.

I've tried changing my declaration for currDir as you mentioned but now when i click the button on my form, my codes cannot be executed. Any idea what could be the cause?

Thanks!
yann
----- Marshall Barton wrote: -----
The Const statement does not accept functions, methods, etc,
it only knows how to interpret expression that use literal
calues and other constants.

You could change that to a string variable:

Public currDir As String

and then assign its value in your startup form:

currDir = CurrentProject.Path
 
M

Marshall Barton

What does "my codes cannot be executed" mean?

And the code currently looks like?

Where is the public variable declared? It must be in the
declarations portion (top) of a standard module, not a
form's module.
 
G

Guest

Hi Marshall,

Thanks. I found out why my codes was not running. I should have assigned the value for my public variable in the Form module which I didn't.

Sorry for my mistake.

Thanks!
yann
 

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