Copying flat vertical records horizontally into another table

rob0r

New member
Local time
Today, 09:47
Joined
Feb 19, 2009
Messages
7
Hello, I’m currently trying to create a function that will look at each record from a single column database table and the record will be copied and distributed into another table depending on the content. I probably haven’t explained myself very well so I’ll demonstrate.

The single column table contains a number of counters, it is written by a machine into a text file. This text file will be automatically imported into my database with an autonumber. We can see the ID column and each counter surrounded by brackets, below each counter is a cycle and a runtime. Each counter is separated by a blank row.

[<Counter1>]
TotalCycles=0
TotalRunTime=000000

[<Counter2>]
TotalCycles=0
TotalRunTime=000000

[<Counter3>]
TotalCycles=0
TotalRunTime=000000

[<Counter4>]
TotalCycles=0
TotalRunTime=000000

However this is no use to me and I want to copy and turn each counter horizontally into an individual record in another table, like so.

Counters Cycles Runtime

[<Counter1>] 0 0
[<Counter2>] 0 0
[<Counter3>] 0 0
[<Counter4>] 0 0


I want to write some VBA code that will look at the source table and copy the records to create the second table. I’ll probably triggering this with the autoexec macro as the database fires. I’ve looked at some DAO codes that will run through the first recordset, but I was wondering if there is a simple way of doing this. I was going to use mid,left or right codes to chop off the titles of the cycles and runtimes. I was also thinking of creating the second table before hand and simply running a delete query everytime the database was opened. Any help in the right direction will be much appreciated.

Thanks,

Rob
 
Thanks for the information, could you be a bit more specific as to how I would do this? I have a working knowledge of various parts of VBA, but I haven't really touched recordsets before.

Many thanks to anyone who can help me.
 
Attached is a sample database that may suit your need.

Have a look at the module mod_create_output

For testing purpose I delete the output table tbl_cycles, you will need to remove the code

Dim sqlcode As String

DoCmd.SetWarnings False
sqlcode = "delete tbl_cycles.* from tbl_cycles"
DoCmd.RunSQL sqlcode
DoCmd.SetWarnings True

It also checks that are three records for each input counter as per
[<Counter1>]
TotalCycles=0
TotalRunTime=000000
 

Attachments

Users who are viewing this thread

Back
Top Bottom