
HELP - Importing Text file into database
Hope this helps
Private Sub cmdImport_Click()
Dim WayBill, PSID, DateShipped As String
Dim sql, sLine As String
Dim Cost As Double
Dim i As Integer
'CD is a common dialog control to find the file which is
on a floppy
With CD
.InitDir = "a:\" 'tell CD where to start
looking for the file
.ShowOpen 'open CD
End With
'open flat file
Open CD.FileName For Input As #1 ''open the text file
Do While Not EOF(1)
Line Input #1, sLine 'take the line into memory
'start parsing the line based on the length of my data and
put them into variables
WayBill = Mid(sLine, 46, 12)
Cost = CCur(Mid(sLine, 72, 6))
DateShipped = "'" & ((Mid(sLine, 58, 8))) & "'"
PSID = Trim((Mid(sLine, 66, 6)))
'create my sql statement
sql = "Insert Into tblCourier
(Cost,DateShipped,waybill,datein) " _
& "Values(" & (Cost * 1.1) * 0.675 & ", " &
DateShipped & ", " & WayBill & ", " & DateShipped & ")"
'execute the sql statement
'I am using a data environment control called de1 with a
connection object called conn2 connected to access 2k
DE1.Conn2.Execute sql
i = i + 1
Loop 'loop to move to the next line and write the
data into the database
'close flat file
Close #1
'display # of packages billed for
MsgBox i & " packages processed!", vbInformation
End Sub
good luck
Quote:
>-----Original Message-----
>Does anyone know how to create an application in visual
>basic, that will take a text file, parcel the information
>and import the data into an Access database or table.
>Please, let me know.
>Paul
>.