|
-
Aug 7th, 2002, 11:59 AM
#1
Thread Starter
Addicted Member
Text In Database
How to put text file in database.
Catholics Do It With Beads
-
Aug 7th, 2002, 12:01 PM
#2
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?
-
Aug 7th, 2002, 01:15 PM
#3
Thread Starter
Addicted Member
Import text file into db table.
Catholics Do It With Beads
-
Aug 7th, 2002, 02:04 PM
#4
Try this...
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
-
Aug 7th, 2002, 02:05 PM
#5
Thread Starter
Addicted Member
Thank you Mr. Hack.
I will try this.
Can this also be used to import text file into Excel?
Catholics Do It With Beads
-
Aug 7th, 2002, 02:19 PM
#6
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|