Results 1 to 3 of 3
  1. #1
    lucky33 is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Sep 2011
    Posts
    2

    Import Excel file into a table

    I have upgraded to Access2013 from 2003 and I have an application that I also upgraded to accdb. Because of a blackout yesterday, my application got corrupted and became unusable. So I opened a backup two weeks old, and when I tried to re-enter the lost data, I was faced with another problem. I use the following code to import a range in an Excel file with one sheet:



    'setting variables to get the file path from table TblLuFilePath
    Dim d As Database
    Dim r As Recordset
    Dim Path As Field
    Set d = CurrentDb()
    Set r = d.OpenRecordset("TblLuFilePath")
    Set Path = r.Fields("FilePath")
    'import range named ToAccess from the Excel file defined in the previous code
    DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
    "TblCardsTrans", Path, True, "ToAccess"

    the code is freezing at the line in red and giving a run-time error 13, type mismatch
    Any suggestions please ???
    George

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    I don't understand use or need for a field object variable but that isn't cause of issue. Don't see problem with the offending line code.

    You open a recordset of all table records. The code looks only at the first record of the recordset. Does this table have only one record?

    An alternative to opening recordset is DLookup.

    Dim Path As String
    Path = DLookup("FilePath", "TblLuFilePath")

    Or no variables at all.
    DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
    "TblCardsTrans", DLookup("FilePath", "TblLuFilePath"), True, "ToAccess"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    lucky33 is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Sep 2011
    Posts
    2

    Thumbs up

    thank you for your reply and solution. you are right, the table has one record only, as i am giving the users choice to place and name the excel file anyway they want. since you gave me a working alternative, i am not going to dwell on why the offending line code is not working anymore
    many thanks again

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

Similar Threads

  1. Replies: 7
    Last Post: 06-30-2014, 12:11 AM
  2. 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
  3. Import Excel file based on a date and time in file name
    By nhylan in forum Import/Export Data
    Replies: 4
    Last Post: 04-16-2013, 03:26 PM
  4. Replies: 5
    Last Post: 01-29-2013, 06:00 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
  •  
Other Forums: Microsoft Office Forums