How to put text file in database.
Printable View
How to put text file in database.
Are you asking how to import a text file into a database or how to take text from a text file and add it to a database record?
Import text file into db table.
VB Code:
Private Sub Command1_Click() Dim db As Database Dim rs As Recordset Dim iLineNo As Integer Dim sFileName As String Dim arrData() As String Const sep = " " Dim SQL As String Dim s As String Dim i As Integer Me.MousePointer = vbHourglass 'file to import sFileName = "D:\Address.TXT" Set db = OpenDatabase("D:\TEST.MDB") 'Create table SQL = "CREATE TABLE Information (Vendor TEXT(50), Name TEXT(255))" db.Execute SQL 'open the table Set rs = db.OpenRecordset("Information") 'open the file and loop through it while importing Open sFileName For Input As #1 Do While Not EOF(1) Line Input #1, s iLineNo = iLineNo + 1 If iLineNo > 9 Then 'the data u want starts on line no 9 arrData = Split(s, vbTab) rs.AddNew rs.Update rs.MoveLast For i = 1 To 2 rs.Edit rs(i - 1) = arrData(i) rs.Update Next i End If Loop Close #1 rs.Close db.Close Set rs = Nothing Set db = Nothing Me.MousePointer = vbNormal MsgBox "Import finished", vbInformation End Sub 'by peet
Thank you Mr. Hack.
I will try this.
Can this also be used to import text file into Excel?
For Excel, see this link
http://forums.vb-world.net/showthrea...hreadid=117718