Results 1 to 4 of 4

Thread: CSV File Import

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    VBAX Newbie
    Joined
    Aug 2018
    Posts
    4
    Location

    Lightbulb CSV File Import - Solution

    Well, I tinkered long enough and found my solution. I modified cmdImport_Click() to the following. fileLocation is now the name of the text box where I am passing the file name and full path to. The cmdImport function then parses the name and directory out.

    Private Sub cmdImport_Click()
        Dim filesystem As Object
        Set filesystem = CreateObject("Scripting.FilesystemObject")
        fileDirectory = filesystem.GetParentFolderName(fileLocation) & "\"
        Dim fileName As String
        fileName = filesystem.GetFileName(fileLocation)
        Set rs = CreateObject("ADODB.Recordset")
        strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & fileDirectory & ";" _
        & "Extended Properties=""text;HDR=Yes;FMT=Delimited"";"
        strSQL = "SELECT * FROM [" & fileName & "] "
        rs.Open strSQL, strConn, 3, 3
        rs.MoveFirst
        Do
            frmBook.FIRSTNAME.Value = rs("FirstName")
            frmBook.LASTNAME.Value = rs("LastName")
            frmBook.MIDDLENAME.Value = rs("MiddleName")
            rs.MoveNext
        Loop Until rs.EOF
        Unload Me
    End Sub
    Last edited by Aussiebear; 03-14-2025 at 10:49 AM.

Posting Permissions

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