Ariel wrote:
Thank you for your reply. Now I have to admit that I've never done
VB in Access and only done a little bit in Excel. Can I ask the dumb
question of what some of these things mean? I think I can understand
some of it - specifically:
(1) dbengine(0)(0) - what does this mean?
(2) rs - is this the name of the new table in Access? Or do you have
to create the new table first and is this just a record set held in
VBA?
(3) What does "dao" mean?
(4) Is "nothing" at the end to reset rs to NULL?
I really appreciate the help and apologize for my ignorance.
Thanks - Ariel
Ariel,
I'll try to keep this simple (perhaps too simple). The code that Piet
posted is a standard technique for adding new records (rows) to a
table. This subroutine would be inside of a loop that grabs the Begin
and End numbers for each record in your start table. For each grab of
Begin and End numbers, the subroutine is called and the appropriate
number of new values are added to the destination table (what you call
your end table). His DestinationField corresponds to the field I call
NPANXX inside of the end table. I forgot to mention that my qryNPANXX
can be changed into a MakeTable query to create an end table if
necessary.
dbEngine(0)(0) starts up the Jet Engine (really) allowing VBA (Visual
Basic for Applications - the VB behind Access) to communicate with the
data. The database object contains code called OpenRecordset that
opens up a recordset object that is used by VBA to communicate with
data in the output (end) table. Note that another recordset object
would need to be opened in the outside loop to communicate with the
start table. DAO stands for Data Access Objects. They're Objects that
can be used to communicate with the data (i.e., Access the Data) such
as the database object or the recordset object you asked about. The
rs.AddNew calls code in the recordset object that creates (but doesn't
save) a new record of Null values. The rs.Update calls code in the
recordset object that saves the changes to the new record (see AddNew
in the Help file). We often specify DAO explicitly since Microsoft
comes up with other ways of communicating with the data and the Access
program sometimes gets confused. The Set rs = nothing is used to
ensure that the RAM memory Access uses to maintain communication with
the data is released. In programming languages such as Visual C++,
failure to release memory can cause memory "leaks" that can hang on to
chunks of RAM making them unusable and slowing down performance until
the machine is rebooted. Access might be able to release the memory
automatically when the subroutine finishes but many Access programmers
have learned not to take too much for granted. I hope this answers
your questions. If not, keep asking questions. Hopefully, before long
you'll be answering our programming questions in this NG.
James A. Fortune
Ariel (n): a prankish spirit in Shakespeare's The Tempest --
www.m-w.com
Fortune (n): the prankish spirit in Shakespeare's Hamlet