Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2012
    Posts
    5

    Unanswered: Is there any way to use parameter for table and browse to Import text file with DoCmd

    I'm trying to import text file in Access DB. Here all are linked table by ODBC from SQL Server. I'm trying with this code as below:
    Code:
    Private Sub cmdUpdate_Click()
        Dim strSelectedFile As Office.FileDialog
        Set strSelectedFile = Application.FileDialog(3)
        strSelectedFile.AllowMultiSelect = False
             
        If strSelectedFile.Show Then
            MsgBox strSelectedFile.SelectedItems.Count & " file(s) were chosen."
            ' Display the full path to each file that was selected
            Dim i As Integer
            For i = 1 To strSelectedFile.SelectedItems.Count
                MsgBox strSelectedFile.SelectedItems(i)
            Next i
        End If
        DoCmd.TransferText acImportDelim, , "" & Me.cboTableList & "", strSelectedFile, 0
    End Sub
    Please help me.

    Thanks
    Mir

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    It should be:
    Code:
    DoCmd.TransferText acImportDelim, , Me.cboTableList.Value, strSelectedFile, 0
    Or, if you want to be really formal:
    Code:
    DoCmd.TransferText acImportDelim, , CStr(Me.cboTableList.Value), strSelectedFile, 0
    Apart from that, what's wrong with your code?

    Note: When you ask for a solution to a problem, please report the error you received (code + description) as well as line on which the error occurs, or explain at least what does not work. This spares us part of the time and work needed to decipher and understand your code.
    Have a nice day!

  3. #3
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    495
    Provided Answers: 24
    If you are importing EVERY file selected, then the TRANSFER must be in the loop.
    Code:
            For i = 1 To strSelectedFile.SelectedItems.Count
                'MsgBox strSelectedFile.SelectedItems(i)
                DoCmd.TransferText acImportDelim, , "" & Me.cboTableList & "", strSelectedFile, 0
            Next i

  4. #4
    Join Date
    Nov 2012
    Posts
    5

    "Run-time error '2391'

    Is there any way solve "Run-time error '2391' Field 'F1' does not exits in destination table", without using importSpec
    Code:
    DoCmd.TransferText acImportDelim, , Me.cboTableList, sFile, False
    I didn't found any help form any where for this problem.

    Please help me!!!!!!!!!!

  5. #5
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14

Posting Permissions

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