Results 1 to 2 of 2
  1. #1
    2 Star Lounger
    Join Date
    Mar 2003
    Location
    London, Gtr London
    Posts
    131
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Importing a file (2003)

    Hi All

    If I want to get my user to select the file they want to import themselves how can I do it?

    I can't remember what the function is called, all I can do is describe it as similar to when on Access/Excel etc. you select FILE and then OPEN and that pop-up box appears so that you can select the path and filename you want to open.

    Many Thanks
    Hayden

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Importing a file (2003)

    If you want to let the user import a file into a table, you can use the instruction

    RunCommand acCmdImport

    for example in the On Click event of a command button. This is equivalent to File | Get External Data | Import. If the user cancels, error 2501 occurs, you must use error handling to suppress the error message. Sample code:

    Private Sub cmdImport_Click()
    On Error GoTo ErrHandler
    RunCommand acCmdImport
    Exit Sub
    ErrHandler:
    If Not (Err = 2501) Then
    MsgBox Err.Description, vbExclamation
    End If
    End Sub

    If you want to let the user pick a file, then handle it yourself, use FileDialog (introduced in Access 2002):

    Private Sub cmdSelect_Click()
    Dim strFilename As String
    With FileDialog(msoFileDialogFilePicker)
    If .Show = True Then
    strFilename = .SelectedItems(1)
    ' code to do something with file goes here
    End If
    End With
    End Sub

    You must set a reference to the Microsoft Office 11.0 Object Library for msoFileDialogFilePicker to be recognised.

Posting Permissions

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