I am going on the presumption that the first value in the text file is the account number, the second is the first name, the third is the last name, and the fourth is the phone number. I am also assuming that you don't need the "Start" and "Width" values in the table. If you do, please let me know.
'-----Code Starts-----
Dim sAccount As String
Dim sFName As String
Dim sLName As String
Dim sPhone As String
...
Set objConn = CreateObject("ADODB.Connection")
Set objRS = CreateObject("ADODB.Recordset")
objConn.Open "DSN=Your DSN;" 'or Use a Provider for Jet to Access
objRS.Open "SELECT * FROM tblYourTable", objConn, 3, 3
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists("C:\data.txt") Then
Set objStream = fso.OpenTextFile("C:\data.txt", 1, False, 0)
End If
Do While Not objStream.AtEndOfStream
strLine = objStream.ReadLine
YourArray = Split(strLine, " ") 'use the tab key to create space between quotes.
sAccount = Trim(YourArray(0))
sFName = Trim(YourArray(1))
sLName = Trim(YourArray(2))
sPhone = Trim(YourArray(3))
objRS.AddNew
objRS("Account") = sAccount
objRS("FirstName") = sFName
objRS("LastName") = sLName
objRS("Phone") = sPhone
objRS.Update
Loop
objConn.Close
objRS.Close
'-----Code Ends-----
As I say, you may want to use DAO instead of ADO.
HTH
mmcdonal
|