Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Constant?

Status
Not open for further replies.

rustychef

Technical User
Sep 2, 2004
63
US
I understand the concept that a CONST variable doesn't change. BUT I want to know if its possible to set the value of a CONST dynamically when the database starts up.

Here's what I want to do: I have a multiuser database. When the db starts up I want to look up the value from a field in a table and store it in the CONST. Once the CONST is set, it does not need to change.

I am using VBA with a 2003 Access database on a network drive, and local drive.

Currently, I am using a GLOBAL variable, and every once in a while the variable loses its value and gets reset to "" to counter this I have inserted an IF statement before every instance of the GLOBAL to check if its value is "", if it is, a DLOOKUP is called.

SO, can I dynamically populate a CONST? I have tried in a class module trying to set it to a DLOOKUP statement, tried setting it to a variable and neither worked.
 
You cannot dynamically set a constant without using what I consider a silly hack. I think you are trying to save the wrong problem. If you have a variable that is magically changing to "" for no apparent reason, I think you need to figure that out.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 

Dynamic Constant, sorry no such thing. Use a variable of appropriate data type. Declare it in module as Public so it could be available in every form, report function, sub etc. When your first form opens, use DLookup() to feed its value.
 
Thanks for the info. I didn't think is was possible, but was still hoping.
EBGREEN: I know why I lose the value when I use the local database (usually when I switch to design view on the form), but the users are locked down and can only use the buttons to close forms, exit, etc. I have asked if they have had a database crash, or tried to open the db exclusively (with the SHIFT key) and all responses are negative. Right now the db is only used by about 4 people, but will expand in the near future.

In the past I have opened the db using the SHIFT/exclusive mode to do some work, then wait to save until everyone is out of the db. While Im working on a form/code if I put the form in design view, can that cause the GLOBAL to lose its value?

Thanks again for the info...
 
Thanks for the info. I didn't think is was possible, but was still hoping.
EBGREEN: I know why I lose the value when I use the local database (usually when I switch to design view on the form), but the users are locked down and can only use the buttons to close forms, exit, etc. I have asked if they have had a database crash, or tried to open the db exclusively (with the SHIFT key) and all responses are negative. Right now the db is only used by about 4 people, but will expand in the near future.

In the past I have opened the db using the SHIFT/exclusive mode to do some work, then wait to save until everyone is out of the db. While Im working on a form/code if I put the form in design view, can that cause the GLOBAL to lose its value?
 
The GLOBAL loose its value each time the VBAProject is reinitialized.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
rustychef said:
In the past I have opened the db using the SHIFT/exclusive mode to do some work, then wait to save until everyone is out of the db.
Your statement suggests you are not using a split frontend/backend solution. Splitting the database and distributing a frontend to each user may be the first step in solving your problem.

However, there must be a bug in your code that is causing the code to crash and this resets your global variables. Your users may be recovering from the crash by simply reopening a form. Putting error handlers in your procedures should aleviate this problem.

 
PHV: Thanks, your statement was enough to job my memory and track down the problem...sometimes my concentration gets so intense I my focus is trapped inside a tiny box and I forget to step out of the box for a better view...
 
JoeAtWork:
Yes I split my database into a front and backend, BUT they're both on the network drive. I mainly split the db to make it easier for me to make updates to the frontend without having to worry about the data in the backend.

I also read something about variables being reset if an untrapped runtime error occurs, and there are runtime errors happening in some of the modules where I didnt trap them.

Should the frontend be on the user's local harddrive, and then have them download a new copy when updates occur? Or is it not that much of a big deal (sorry for my ignorance on that part...not a lot of experience in networking/multi-user databases)
 



"Dynamic Constant"

I can remember freshmen physics lab as if it were yesterday, rather than 48 years ago.

There I discovered, Finagle's Variable Constant.

This "Dynamic Constant," must be a derivative or corollary function related to Finagle.


Skip,

[glasses]I'll be dressed to the nines this week, as I go to have my prostatectomy...
Because, if I'm gonna BE impotent, I want to LOOK impotent![tongue]
 
I'm just Finagle would approve of the concept at least.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
A dynamic constant is a constant that has met and married an uncertainty principle.
 



So that's where the "String him along" theory comes from. Hmmmmmmmmmm????

Skip,

[glasses]I'll be dressed to the nines this week, as I go to have my prostatectomy...
Because, if I'm gonna BE impotent, I want to LOOK impotent![tongue]
 
rustychef

>Should the frontend be on the user's local harddrive
Yes

>have them download a new copy when updates occur
Check out the Multi User Databases section of the FAQ in this forum.

I also have a VB6 version of this, that checks for the map drive letter and if doesnt exist tries to create it. Users copy the exe and use it to open a secured split database with their FE on theirs PC. So they don't mess with the path, which mdb to open and the mdw is not requiered to be already joinned!
 
I think you can avoid loosing a value in global variabel if you run into an unmanaged error by storing it somewhere in the registry... Well atleast that is what i read ;-)

Pampers [afro]
Keeping it simple can be complicated
 
How are ya rustychef . . .

Store the value in a [blue]Custom Db[/blue] property! . . . Their non-volatile! . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top