GaelicFatboy
Registered User.
- Local time
- Today, 20:32
- Joined
- Apr 17, 2007
- Messages
- 100
Hi Chaps & Chapesses,
I have some code to perform a lengthy task of reading a text file and adding the data to fields within various table's record. The text file is long, the field names are varied and the tables are numerous.
I have some code to load the text file data into a collection which stores the table name, field name and data value. I then open the associated table and add the data in the following manner…
“clsImport” is a class storing table names.
“colSD” is a class collection storing the system data.
Set daoDBase = CurrentDb
Set daoRecSet = daoDBase.OpenRecordset(clsImport.Tblname, dbOpenDynaset)
With daoRecSet
.AddNew
![Name] = colSD(“name”).DataVal
![Address1] = colSD(“address1”).DataVal
![Address2] = colSD(“address2”).DataVal
![Pcode] = colSD(“pcode”).DataVal
{so on and so forth for each table at a time}
.Update
.Close
End With
Set daoRecSet = Nothing
daoDBase.Close
set daoDBase = Nothing
Set colSD = Nothing
Set clsImport = Nothing
What I would like to do instead of having to type each of the field names is to replace them with a variable or property stored in a collection and shorten the code to this…
Set daoDBase = CurrentDb
Set daoRecSet = daoDBase.OpenRecordset(clsImport.Tblname, dbOpenDynaset)
With daoRecSet
.AddNew
For intX = 1 to colSD.Count
![colSD(intX).FieldName] = colSD(intX).DataVal
Next
.Update
.Close
End With
Set daoRecSet = Nothing
daoDBase.Close
set daoDBase = Nothing
Set colSD = Nothing
Set clsImport = Nothing
I’ve tried various options for the “.FieldName” but none of my attempts have been successful. Any ideas?
Thanks for your help.
Cheers
D
I have some code to perform a lengthy task of reading a text file and adding the data to fields within various table's record. The text file is long, the field names are varied and the tables are numerous.
I have some code to load the text file data into a collection which stores the table name, field name and data value. I then open the associated table and add the data in the following manner…
“clsImport” is a class storing table names.
“colSD” is a class collection storing the system data.
Set daoDBase = CurrentDb
Set daoRecSet = daoDBase.OpenRecordset(clsImport.Tblname, dbOpenDynaset)
With daoRecSet
.AddNew
![Name] = colSD(“name”).DataVal
![Address1] = colSD(“address1”).DataVal
![Address2] = colSD(“address2”).DataVal
![Pcode] = colSD(“pcode”).DataVal
{so on and so forth for each table at a time}
.Update
.Close
End With
Set daoRecSet = Nothing
daoDBase.Close
set daoDBase = Nothing
Set colSD = Nothing
Set clsImport = Nothing
What I would like to do instead of having to type each of the field names is to replace them with a variable or property stored in a collection and shorten the code to this…
Set daoDBase = CurrentDb
Set daoRecSet = daoDBase.OpenRecordset(clsImport.Tblname, dbOpenDynaset)
With daoRecSet
.AddNew
For intX = 1 to colSD.Count
![colSD(intX).FieldName] = colSD(intX).DataVal
Next
.Update
.Close
End With
Set daoRecSet = Nothing
daoDBase.Close
set daoDBase = Nothing
Set colSD = Nothing
Set clsImport = Nothing
I’ve tried various options for the “.FieldName” but none of my attempts have been successful. Any ideas?
Thanks for your help.
Cheers
D