I need to create a constants table that exists entirely in VB code.
The table consists of 3 columns and 5 rows
I want the table to look like this:
ID Start Finish
1 3/1/07 3/5/07
2 3/6/07 4/10/07
...etc.
I then want to have code to pull out values in the table e.g.
GetStart(1) would use the Dlookup function to return the value in the
"Start" from the row with id "1". I'm pretty confident I can program
this portion of it.
What I don't know how to do is declare this table to exist in VB. Do
I want a table? Do I want an array instead? What is the best way to
go about this?
Thanks
Well, DLookup doesn't work except with tables and select queries, so you'd have
to use different programming methods to get to the data if it were totally
contained within VBA code. And VBA doesn't allow you to define an array of
constants because there is no valid syntax to initialize their values at
declaration time (in C or C++, you can). Therefore, you will most likely be
happier using a table.
Whenever you define constants in VBA code, you will have to change them within
the VBA code modules. If the front end is split from the back end, and you have
15 clients sharing the same data, for example, then each client will (should!)
have their own copy of the code modules. That means that whenever one of the
"constant" values needs to change, you will have to update all 15 client MDB
files (or maybe 150 as the case may be, although that is not a realistic figure
for applications which use Access as a back end). Not a very pretty scenario
(especially if you have distributed MDE files to the clients)!
However, you CAN store these "constant" values in a table residing in theback
end (i.e. one single MDB file containing all the data needed by the clients) and
share them by having the clients link to the tables. That way, whenever
something changes (believe me, something WILL change sooner or later!), you will
have only one update to do (and you can use DLookup as well).
However, as to the "constantness" of the data, you have to fake it by using the
built-in permissions mechanisms of Access. This in itself might be more overkill
than you are willing to accept. But if your users are few in number and not
malicious, then you could probably get away with just putting the tables with
the "constant" data into a separate MDB file and linking them into the other
applications. Set the file properties of that MDB in Windows to read-only, and
nobody will be able to change the data in it (unless they know how to reset the
Windows read-only flag -- which is pretty easy to do, of course <g>).