Results 1 to 6 of 6

Thread: Text In Database

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2002
    Location
    Rome, Italy
    Posts
    150

    Text In Database

    How to put text file in database.
    Catholics Do It With Beads

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    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?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2002
    Location
    Rome, Italy
    Posts
    150
    Import text file into db table.
    Catholics Do It With Beads

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Try this...

    VB Code:
    1. Private Sub Command1_Click()
    2.  
    3.     Dim db As Database
    4.     Dim rs As Recordset
    5.     Dim iLineNo As Integer
    6.     Dim sFileName As String
    7.     Dim arrData() As String
    8.     Const sep = " "
    9.     Dim SQL As String
    10.     Dim s As String
    11.     Dim i As Integer    
    12.  
    13.     Me.MousePointer = vbHourglass
    14.      'file to import
    15.     sFileName = "D:\Address.TXT"
    16.  
    17.     Set db = OpenDatabase("D:\TEST.MDB")  
    18.  
    19.     'Create table
    20.  
    21.     SQL = "CREATE TABLE Information (Vendor TEXT(50), Name TEXT(255))"
    22.     db.Execute SQL
    23.  
    24.     'open the table
    25.     Set rs = db.OpenRecordset("Information")  
    26.     'open the file and loop through it while importing
    27.  
    28.     Open sFileName For Input As #1
    29.     Do While Not EOF(1)
    30.         Line Input #1, s
    31.         iLineNo = iLineNo + 1
    32.         If iLineNo > 9 Then 'the data u want starts on line no 9
    33.             arrData = Split(s, vbTab)
    34.             rs.AddNew
    35.             rs.Update
    36.             rs.MoveLast
    37.  
    38.             For i = 1 To 2
    39.                 rs.Edit
    40.                 rs(i - 1) = arrData(i)
    41.                 rs.Update
    42.             Next i
    43.  
    44.         End If
    45.  
    46.     Loop
    47.  
    48.     Close #1  
    49.     rs.Close
    50.     db.Close
    51.     Set rs = Nothing
    52.     Set db = Nothing
    53.  
    54.     Me.MousePointer = vbNormal
    55.     MsgBox "Import finished", vbInformation
    56.  
    57. End Sub
    58. 'by peet

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2002
    Location
    Rome, Italy
    Posts
    150
    Thank you Mr. Hack.

    I will try this.

    Can this also be used to import text file into Excel?
    Catholics Do It With Beads

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width