values stored for lifetime of database

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I define values in VB that are stored on C drive and I can close and
reopen the database and values remain until I change them?
 
elburze said:
How do I define values in VB that are stored on C drive and I can close and
reopen the database and values remain until I change them?


This is usually done by using a table. Some people prefer
to use two fields one for the name and the other for the
value. You can then retrieve a single value using a
DLookup:

myvar = DLookup("valvalue", "vartable", "varname='myvar' ")

Other folks prefer to use a one row table with a separate
field for each value. The DLookup in this case would be:

myvar = DLookup("myvar", "vartable")

but this latter approach requires you to mofify the table's
design whenever you need to add another variable.

In either case, if you need to retrieve all the values at
one time, you should open a recordset so you can directly
access the record(s) .

You can set the values by either Executing an Update query
or by opening a recordset and Editing the record(s).
 
How do I define values in VB that are stored on C drive and I can
close and reopen the database and values remain until I change them?

I use database properties: you can either use

dim db as DAO.database
set db = currentdb()
debug.print db.properties(propertyName)

which can only be accessed via VBA, or you can use

currentdb().containers("Databases"). _
Documents("UserDefined"). _
Properties(propertyName)

which refers to the properties you can see when you click File ->
Database properties -> Custom, so that the user can update or debug them.

Failing that, you can use an old-fashioned INI file, for which there are
loads of API hooks available for VBA. Again, this has the advantage or
disadvantage of being user-readable and user-editable.

Hope that helps

Tim F
 
Back
Top