HOW-TO: use a function in declaring a user-defined constant ???

B

bobg

running access 2k in FE/BE arrangement;

I have created a function in my FE that gets the path to the BE using
TD.connect...

what I would LIKE to do, is declare a constant ie: MYDBPATH, that
contains the path extracted from the .connect string.

ie:
fGetPath() returns something like "d:\data\dbdata\mydb-data.mdb"

I would like to:
public const MYDBPATH as string = fGetPath()

access doesn't appear to allow procedure calls in a const declaration
statement.

How would I accomplish what I want?

tia - Bob
 
G

Gerald Stanley

If you open a form upon start-up, put the code to set the
variable in the form's Open eventhandler. If you run a
code module, include the code in that.

Hope This Helps
Gerald Stanley MCSD
 
D

Dirk Goldgar

bobg said:
running access 2k in FE/BE arrangement;

I have created a function in my FE that gets the path to the BE using
TD.connect...

what I would LIKE to do, is declare a constant ie: MYDBPATH, that
contains the path extracted from the .connect string.

ie:
fGetPath() returns something like "d:\data\dbdata\mydb-data.mdb"

I would like to:
public const MYDBPATH as string = fGetPath()

access doesn't appear to allow procedure calls in a const declaration
statement.

How would I accomplish what I want?

tia - Bob

You can't call a function in a Const declaration. One way to do what you
want is to declare MyDBPath as a public property in a standard module. For
example, consider this code:

'----- start of module code -----
Option Compare Database
Option Explicit

Dim mDBPath As String

Public Property Get MyDBPath() As String

If Len(mDBPath) = 0 Then
mDBPath = fGetPath()
End If

MyDBPath = mDBPath

End Property
'----- end of module code -----
 
B

bobg

Dirk Goldgar said:
You can't call a function in a Const declaration. One way to do what you
want is to declare MyDBPath as a public property in a standard module. For
example, consider this code:

'----- start of module code -----
Option Compare Database
Option Explicit

Dim mDBPath As String

Public Property Get MyDBPath() As String

If Len(mDBPath) = 0 Then
mDBPath = fGetPath()
End If

MyDBPath = mDBPath

End Property
'----- end of module code -----

thanks to those that responded....
your answers led me down the path that gave me the answer I ideally wanted...

replace line....

it allows me to "reset" a constant, from within the code....

tx again to all!!
 

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