Good Afternoon,
I'm working with comma-delimited CSV files, trying to import the contents into 2 related tabled (1-Many). I've done quite a bit of looking today, both here and in Help, but did not see the answer I needed. I've attached a copy of typical CSV file that I'm working on. The first field in the CSV file goes into the "One" table, which has an autonumber ID, date field, and labID field. It should go into the labID field. The second and third fields go into the "Many" table.
My question is; how do I tell Access in the code which field in the CSV file is which? In the attached file, the first field says "NBS 59a". This is a name which will go into the "One" table as the labID.
Here is some code I'm working with:
For labID, I did not know how to reference it from the CSV file, other than to say (field1). It does not work, so it must not be correct. Could anyone be kind enough to tell me how to refer to the first field in my CSV file in this code?
Thank you in advance.
I'm working with comma-delimited CSV files, trying to import the contents into 2 related tabled (1-Many). I've done quite a bit of looking today, both here and in Help, but did not see the answer I needed. I've attached a copy of typical CSV file that I'm working on. The first field in the CSV file goes into the "One" table, which has an autonumber ID, date field, and labID field. It should go into the labID field. The second and third fields go into the "Many" table.
My question is; how do I tell Access in the code which field in the CSV file is which? In the attached file, the first field says "NBS 59a". This is a name which will go into the "One" table as the labID.
Here is some code I'm working with:
Code:
Dim dbs As DAO.Database 'Pull up database
Dim rst As DAO.Recordset 'Pull up individual recordset for table
Dim lecoID As Long 'The AutoNumber record ID
Dim labID As String 'The assigned LAB ID (labID) of the sample
Dim analysisdate As Date 'Date of analysis
Dim concentration As Double 'Result concentration, in %, from the analysis
Dim analyte As String 'Name of the analyte
Dim SQL As String 'The SQL statement used to pull data into the table "tblLecoAnalysisDetails"
Dim buffer As String
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblLECOAnalysis") 'Set database table
DoCmd.SetWarnings False 'Turn off warning so that an Access message box does not appear
'for each record appended to the "tblLecoAnalysisDetails" table
Open "C:\Results\LECO.csv" For Input As #1 'Open the text file made by LECO to
'import the data
Line Input #1, buffer
While Not EOF(1)
labID = (Field1) 'Tells where on this line to grab for labID
Set rst = dbs.OpenRecordset("tblLECOAnalysis") 'Opens table tblLECOAnalysis
rst.AddNew 'new record set for data import
lecoID = rst!lecoID 'Save the AutoNumber, we'll need it below
rst!labID = labID 'Saves labID to labID field in table
rst!analysisdate = date 'Saves actual date of import to sdate field in table (note, don't use reserved word "date" for object
For labID, I did not know how to reference it from the CSV file, other than to say (field1). It does not work, so it must not be correct. Could anyone be kind enough to tell me how to refer to the first field in my CSV file in this code?
Thank you in advance.