G
Guest
I have written some VB code attached to a button on a form that imports 2
tables from a another database, and appends any new values to equivalent
tables in the current database. Within the same code, I would like to create
a table that lists the number
of records that were successfully added to each table.
I thought I could use a call to DCount at the beginning of my code to create
variables that contain the record count of each table before the code runs,
and then use DCount again at the end to count the records now in each table.
Then I could calculate the difference. However I am pretty new to VB and am
unsure how to put the resulting calculated values in a table (or even assign
them to any kind of object?)… also, if there is a much more efficient way to
do this let me know, because the DCount seems a bit slow when it runs…
My tables are “LogData†(with Primary key a combination of the fields
“LoggerID†& “LogUTCâ€) and “Readings†(with Primary key a combination of the
fields “LoggerID†& “ReadingFromâ€).
My code is currently as follows:
Private Sub command1_Click()
Dim LogDataCountStart As Long
LogDataCountStart = DCount("LoggerID & LogUTC", "LogData")
Dim ReadingsCountStart As Long
ReadingsCountStart = DCount("LoggerID & ReadingFrom", "Readings")
…. Rest of code that runs the SQL for the append queries that actually adds
the data, I have tested this and it works fine….
Dim LogDataCountEnd As Long
LogDataCountEnd = DCount("LoggerID & LogUTC", "LogData")
Dim ReadingsCountEnd As Long
ReadingsCountEnd = DCount("LoggerID & ReadingFrom", "Readings")
Dim NewLogData As Long
NewLogData = LogDataCountStart - LogDataCountEnd
Dim NewReadings As Long
NewReadings = ReadingsCountStart – ReadingsCountEnd
End Sub
tables from a another database, and appends any new values to equivalent
tables in the current database. Within the same code, I would like to create
a table that lists the number
of records that were successfully added to each table.
I thought I could use a call to DCount at the beginning of my code to create
variables that contain the record count of each table before the code runs,
and then use DCount again at the end to count the records now in each table.
Then I could calculate the difference. However I am pretty new to VB and am
unsure how to put the resulting calculated values in a table (or even assign
them to any kind of object?)… also, if there is a much more efficient way to
do this let me know, because the DCount seems a bit slow when it runs…
My tables are “LogData†(with Primary key a combination of the fields
“LoggerID†& “LogUTCâ€) and “Readings†(with Primary key a combination of the
fields “LoggerID†& “ReadingFromâ€).
My code is currently as follows:
Private Sub command1_Click()
Dim LogDataCountStart As Long
LogDataCountStart = DCount("LoggerID & LogUTC", "LogData")
Dim ReadingsCountStart As Long
ReadingsCountStart = DCount("LoggerID & ReadingFrom", "Readings")
…. Rest of code that runs the SQL for the append queries that actually adds
the data, I have tested this and it works fine….
Dim LogDataCountEnd As Long
LogDataCountEnd = DCount("LoggerID & LogUTC", "LogData")
Dim ReadingsCountEnd As Long
ReadingsCountEnd = DCount("LoggerID & ReadingFrom", "Readings")
Dim NewLogData As Long
NewLogData = LogDataCountStart - LogDataCountEnd
Dim NewReadings As Long
NewReadings = ReadingsCountStart – ReadingsCountEnd
End Sub