Results 1 to 4 of 4

Thread: Access vba - import excel

  1. #1

    Thread Starter
    Member chrisguk's Avatar
    Join Date
    Nov 2011
    Posts
    61

    Access vba - import excel

    Hi there,

    I currently have a simple vba function which assists me with importing my excel spreadsheet into pre-defined tables in access. But I want to make it more professional.

    This is my current code:

    Code:
    docmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel7, "tblname", "myfilename", True
    What I want to happen is once the import button has been clicked a windows folder/dialogue pops up for you to select the file you wish to import.

    Is there a way to do this?

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Access vba - import excel

    try like
    vb Code:
    1. myfilename = application.getopenfilename
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Member chrisguk's Avatar
    Join Date
    Nov 2011
    Posts
    61

    Re: Access vba - import excel

    Hi and thanks for the reply.

    How and where would I put this code?

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Access vba - import excel

    immediately before the docmd line
    replace the "myfilename" string in the docmd, with the myfilename variable

    you probably need some handling for if the user presses cancel in the dialog
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width