PSUIVERSON
Technical User
I have setup a Macro that imports a text file into Access. Because the field names are not in the text file I cannot just name the fields based off the first row of the text file. I am relatively new to VBA programming in ACCESS and wanted to try and shoot the macro to code and call a function out of a module. I am having a small problem with figuring out how to grab recordsets from this new table and then figuring out how to name the fields?
Example:
Sub nameField()
Dim db As Database
Dim rst As Recordset
'How to open table and how to write to field names how do I do this?
'Rough Guess:
Set db = CurrentDb
Set rst = db.OpenRecordset("TABLE_NAME_FROM_IMPORT"
'With the database open I now have no idea how to name the FIELD NAMES?!
'Rough Guess with 3 fields!?
rst.Fields.Item.Name = "FIELD1"
rst.MoveNext
rst.Fields.Item.Name = "FIELD2"
rst.MoveNext
rst.Fields.Item.Name = "FIELD3"
rst.MoveFirst
Set rst = db.Close
End Sub
Example:
Sub nameField()
Dim db As Database
Dim rst As Recordset
'How to open table and how to write to field names how do I do this?
'Rough Guess:
Set db = CurrentDb
Set rst = db.OpenRecordset("TABLE_NAME_FROM_IMPORT"
'With the database open I now have no idea how to name the FIELD NAMES?!
'Rough Guess with 3 fields!?
rst.Fields.Item.Name = "FIELD1"
rst.MoveNext
rst.Fields.Item.Name = "FIELD2"
rst.MoveNext
rst.Fields.Item.Name = "FIELD3"
rst.MoveFirst
Set rst = db.Close
End Sub