+ Reply to Thread
Results 1 to 9 of 9

Search for and select and database to import to excel

  1. #1
    Registered User
    Join Date
    01-07-2008
    Location
    Northampton, UK
    MS-Off Ver
    version 2212, office 365 enterprise
    Posts
    74

    Smile Search for and select and database to import to excel

    Hi all,

    I have a code which imports data from a certain database, see below:

    Please Login or Register  to view this content.
    However, I want the user to be able to specify the database using an input box, or a combo-box or something similar. I know its possible but I'm a little stuck. Basically, I would like the user to only have to put in the name of the database (as they will all be in the same folder).

    Any Ideas?

    *Apologies for the grammatical error in the title*
    Last edited by chrismann85; 05-19-2008 at 04:29 AM.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482
    You can use the GetOpenfilename method, which will display a dialog that allows you to select a file and or change folders.

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    01-07-2008
    Location
    Northampton, UK
    MS-Off Ver
    version 2212, office 365 enterprise
    Posts
    74

    Thumbs up

    Thanks Andy, I'm not sure where exactly in my code to put this. I have tried to run it on its own to see what it does but I get an error on the Line
    Please Login or Register  to view this content.
    Does this just open the file? I want to use it with my macro to import the data to my current worksheet (the data originates from Access if that makes any difference).

    Thanks again,

    Chris

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482
    It would go at the top of your code.
    GetOpenfilename does not open any files it just displays the dialog and returns file(s) selected by the user.
    The returned value would be incorporated in to your query.

    Please Login or Register  to view this content.
    The error could be because the value in strPath is a folder that does not exist. Make sure the folder name is correct.

  5. #5
    Registered User
    Join Date
    01-07-2008
    Location
    Northampton, UK
    MS-Off Ver
    version 2212, office 365 enterprise
    Posts
    74
    I'm still getting an error:

    Run Time Error '76': Path not found

    The error is on the line
    Please Login or Register  to view this content.

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482
    So is this the folder where the data should be?

    "C:\Documents and Settings\cmann29\My Documents\2007 Test Converter Tool\"

    If not replace it with the correct folder name.

  7. #7
    Registered User
    Join Date
    01-07-2008
    Location
    Northampton, UK
    MS-Off Ver
    version 2212, office 365 enterprise
    Posts
    74
    The directory is correct, I've removed the line and it seems to do as you said it would. I'm still having issues, I think it is because I specify the file using you code at the beginning, then when my part of the code is used, it specifies a different database and it gets confused. Do I need to modify something in my code to tell it to use the file specified at the beginning?

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482
    Yes you need to modify the query. See post #4 in this thread where I replaced the hard coded reference with the variable vntFile.

  9. #9
    Registered User
    Join Date
    01-07-2008
    Location
    Northampton, UK
    MS-Off Ver
    version 2212, office 365 enterprise
    Posts
    74

    Thumbs up

    Sorry Andy, I didn't notice that you changed that, I put it into my code and it works like a charm.

    I can't thank you enough

    Cheers,

    Chris

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1