Hi all!
this is my first time playing with code and I need a little help
I'm importing from a text file into a table
the structure of the text file looks like this;
3031,Obecid = QrABAik, type = P, Obec Label = LIIITS, COLOUR = 255, LITCRR = 9, QBNAM = LA, SIPRIP = (1), SIPPER = 2.5, SIDGET = 2002, SIDEND = UPDATE, SCALAQ = 60000, Spatial
3032,Obecid = QgABAik, type= P, Obec Label = LIIITS, COLOUR = 443, LITCRR = 2, OBNAM = Krotz, SIPRIP = (1), SIPPER = 2.5, SIDGET = 2002, SIDEND = 1989, SCALAQ = 60000,
3033,Obecid = QwABAik, type = P, Obec Label = QARZTS, LITCRR = 21, SIDGET = 2001, SIDEND = NONE, COLOUR = 255, SCALAQ = 60000,
this is the code I'm trying to use ;
Function ImportTable()
Dim dbs As Database, rst As Recordset
Dim Directory As String
Dim MyString As String
DoCmd.SetWarnings False
DoCmd.RunSQL "Delete * from Table1"
DoCmd.SetWarnings True
Set dbs = CurrentDb
Directory = (Mid(dbs.Name, 1, Len(dbs.Name) - Len(Dir(dbs.Name))))
Open Directory & "\Zoolu1qut.txt" For Input As #1
Set rst = dbs.OpenRecordset("Table1")
Do While Not EOF(1)
Line Input #1, MyString
rst.AddNew
rst!OBECID = Left(MyString, InStr(MyString, "obecid =") - 1)
MyString = Mid(MyString, InStr(MyString, " ") + 1)
rst!OBECLABEL = Left(MyString, InStr(MyString, "obec label") + 1)
MyString = Mid(MyString, InStr(MyString, " ") + 1)
rst.Update
Loop
MsgBox "Done!"
Close #1
rst.Close
Set dbs = Nothing
End Function
Believe me I have no idea what i'm doing , what I'm trying to do is using the do while loop above, add all of the values form the text file to the correct field in the table.
what do I need to add or change in the loop to do this?
thanks!
Murlen
this is my first time playing with code and I need a little help
I'm importing from a text file into a table
the structure of the text file looks like this;
3031,Obecid = QrABAik, type = P, Obec Label = LIIITS, COLOUR = 255, LITCRR = 9, QBNAM = LA, SIPRIP = (1), SIPPER = 2.5, SIDGET = 2002, SIDEND = UPDATE, SCALAQ = 60000, Spatial
3032,Obecid = QgABAik, type= P, Obec Label = LIIITS, COLOUR = 443, LITCRR = 2, OBNAM = Krotz, SIPRIP = (1), SIPPER = 2.5, SIDGET = 2002, SIDEND = 1989, SCALAQ = 60000,
3033,Obecid = QwABAik, type = P, Obec Label = QARZTS, LITCRR = 21, SIDGET = 2001, SIDEND = NONE, COLOUR = 255, SCALAQ = 60000,
this is the code I'm trying to use ;
Function ImportTable()
Dim dbs As Database, rst As Recordset
Dim Directory As String
Dim MyString As String
DoCmd.SetWarnings False
DoCmd.RunSQL "Delete * from Table1"
DoCmd.SetWarnings True
Set dbs = CurrentDb
Directory = (Mid(dbs.Name, 1, Len(dbs.Name) - Len(Dir(dbs.Name))))
Open Directory & "\Zoolu1qut.txt" For Input As #1
Set rst = dbs.OpenRecordset("Table1")
Do While Not EOF(1)
Line Input #1, MyString
rst.AddNew
rst!OBECID = Left(MyString, InStr(MyString, "obecid =") - 1)
MyString = Mid(MyString, InStr(MyString, " ") + 1)
rst!OBECLABEL = Left(MyString, InStr(MyString, "obec label") + 1)
MyString = Mid(MyString, InStr(MyString, " ") + 1)
rst.Update
Loop
MsgBox "Done!"
Close #1
rst.Close
Set dbs = Nothing
End Function
Believe me I have no idea what i'm doing , what I'm trying to do is using the do while loop above, add all of the values form the text file to the correct field in the table.
what do I need to add or change in the loop to do this?
thanks!
Murlen