Results 1 to 4 of 4
  1. #1
    mathanraj76 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Posts
    39

    Open file from current Directory

    Hi..
    I need help

    I have a folder and inside this folder i have ms database and with all excel file which need to import into access database table



    So what i want to do here is when i click the command button then ms access will upload the excel file into table from the current folder even though i move the whole folder into another computer..
    still ms access able to upload the data from the current folder..

    Thanks
    Mraj

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    You can use the wizard to create an import procedure and save the procedure with a name. With that you can call the name using Docmd.

    Here is some code I use to loop through a folder on a server and grab all of the text files it can find. It imports the text files using the procedure I created using the wizard. The name I gave the procedure is "CustomSpec". If your files are .txt or .CSV then DoCmd.TransferText will work. Otherwise you will need something like DoCmd.TransferSpreadsheet acImport.


    Code:
    Dim strFilename As String
    Dim strPath As String
    
    strPath = "\\ServerName\FolderName\"
    strFilename = Dir(strPath + "*.txt", vbHidden) 'gets first txt file in path specified
    Do While strFilename <> ""   'will cause to loop through all txt files in path
    DoCmd.TransferText acImportFixed, "CustomSpec", _
    "tblImportStuff", strPath & strFilename, 0
    Kill strPath & strFilename
    strFilename = Dir   'grabs next txt file
    Loop

  3. #3
    mathanraj76 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Posts
    39
    I'm not using server but using desktop pc..
    The whole folder is on my pc desktop and if i copy this folder and put into another pc desktop
    still the ms access able to import the excel files from the current folder into table..

    Thanks
    Mraj

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    If it is networked, you can place the PC name or its IP in place of "ServerName". Maybe you can start by using the wizard to import a single file on your PC. Once you have that you can take more steps towards your ultimate goal.

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

Similar Threads

  1. fDialog to open a Directory, Sort by Date Modified
    By GovtWerker in forum Programming
    Replies: 1
    Last Post: 10-11-2013, 11:06 AM
  2. Replies: 10
    Last Post: 10-07-2013, 08:20 AM
  3. Get current record when open an excel file
    By majinon2012 in forum Programming
    Replies: 1
    Last Post: 06-12-2012, 10:32 AM
  4. CurDir() doesn't give current directory
    By bdaniel in forum Programming
    Replies: 4
    Last Post: 12-20-2011, 09:08 PM
  5. Parse a File from a Directory and write data to table
    By galahad in forum Database Design
    Replies: 0
    Last Post: 04-23-2009, 08:38 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