Results 1 to 7 of 7
  1. #1
    GerryP is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2012
    Posts
    5

    Question Importing a user specified spreadsheet and range into Access 2007 Help required.

    Hi, Firstly I am an absolute novice with respect to VB Coding.... so please be gentle !



    This is what I would ideally like to do.

    From an 'Import' button on an Access form:
    1. Be asked to select the spreadsheet name (i.e. list xls files from the hard drive as the spreadsheet names will change over time)
    2. Be asked for the range to import e.g A1:AF20 (this will change and therefore cannot be hard coded)
    3. Import the specified range into a specific Access table called 'RC Data'
    4. Confirm that the data has been imported (Just a Msg)

    Additional Info. The spreadsheets will contain multiple worksheets but the required worksheet will always be called 'Survey'.

    I'm thinking something like the 'DoCmd.TransferSpreadsheet' will work but I just don't know how to go about the coding to achieve the above.

    Any help would be really appreciated.

    Thanks
    Gerry

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Use a form to input the import specifications then VBA code to concatenate reference to controls on form into the TransferSpreadsheet action statement.

    DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "[RC Data]", "your file path/" & Me.txtSheetName, , Me.txtStartRange & ":" & Me.txtEndRange

    http://msdn.microsoft.com/en-us/libr...ffice.10).aspx

    Displaying the list of Excel files from directory into a combobox RowSource is another issue. http://www.everythingaccess.com/tuto...es-recursively
    Last edited by June7; 07-22-2012 at 10:07 AM.
    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
    GerryP is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2012
    Posts
    5
    Thanks June7

    I get a compile error msg (Method or Data Member Not Found) and Me.txtSheetName highlighted when I run the code. Do I have to DIM the statement 'Me.txtSheetName' as a string at the beginning of the code?

    Many thanks

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    No, txtSheetName is just my generic example for a textbox on a form, as are txtStartRange and txtEndRange. Use your actual names.
    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.

  5. #5
    GerryP is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2012
    Posts
    5
    Hi June7
    Ah, that makes sense now (apologies for being slow). I've done the form and I can get the data into the table now which is great. One last question if I can. Is there an easy way of searching for the xls file without having type in the path and filename? I guess what would be utopia would be for the code to open the windows directory and then you can browse for/select the file that you want. No problem if it's not easy or practical, at least I can now get the data imported and the ranges are variable.

    Many thanks

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    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.

  7. #7
    GerryP is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2012
    Posts
    5
    That's great, Thanks for all you help June7

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

Similar Threads

  1. Replies: 13
    Last Post: 11-18-2013, 02:20 PM
  2. Importing Excel Spreadsheet
    By JayX in forum Access
    Replies: 2
    Last Post: 12-13-2011, 08:27 AM
  3. Only importing a specific spreadsheet-vba
    By Lorlai in forum Access
    Replies: 1
    Last Post: 09-08-2011, 05:26 PM
  4. Importing Spreadsheet
    By derfalpha in forum Access
    Replies: 1
    Last Post: 01-04-2011, 10:47 AM
  5. Importing Excel 2007 spreadsheet into Access 2002
    By jhjr in forum Import/Export Data
    Replies: 1
    Last Post: 06-17-2010, 02:05 PM

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