Results 1 to 2 of 2
  1. #1
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2016
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    619

    Import Excel File Into Access

    Hi - I am trying to use the below code to import an Excel file into my access database, but I get the error
    Run-time error '424':
    Object required

    On the line
    Code:
    For Each importPath In .SelectedItems
    Maybe my code is not the best, but how can someone here recommend I set this up to allow the user to select ONE .csv or one .xls or one .xlsx file to import?



    Code:
    Function GetFile()
    Dim sMyPath As FileDialog
    Dim sPath As Variant
    
    
    DoCmd.SetWarnings False
    DoCmd.Hourglass True
    
    Set sMyPath = Application.FileDialog(msoFileDialogFilePicker)
    
    With sMyPath
    
    .AllowMultiSelect = False
    
    .Title = "Select your File"
    
    .Filters.Add "All Files", "*.*"
    
    
    If .Show = -1 Then
    For Each sPath In .SelectedItems
    
    
    DoCmd.TransferSpreadsheet acImport, "tblName", "Equipment", sPath, True
    Next sPath
    Else
    MsgBox "Please pick a file to import"
    End If
    
    End With
    DoCmd.SetWarnings True
    DoCmd.Hourglass False
    
    
    End Function

  2. #2
    GinaWhipp's Avatar
    GinaWhipp is offline Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Jul 2011
    Location
    Ohio, USA
    Posts
    374
    Hmm, the first thing I noticed was sMyPath is the where the file is but in your code you refer to it as sPath. So which one is it?

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 34
    Last Post: 08-09-2017, 09:57 AM
  2. Import Excel file to MS Access
    By subhasmita in forum Import/Export Data
    Replies: 3
    Last Post: 07-27-2017, 03:24 PM
  3. Replies: 2
    Last Post: 02-28-2017, 01:34 AM
  4. Import access query data into excel file, using excel vba
    By exceljockey in forum Import/Export Data
    Replies: 3
    Last Post: 11-15-2013, 02:36 PM
  5. Import Excel file to Access
    By emmett in forum Import/Export Data
    Replies: 3
    Last Post: 04-06-2012, 05:27 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
  •  
Tech Forums: Microsoft Office Forums