Results 1 to 4 of 4
  1. #1
    vanthien is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Jan 2013
    Posts
    21

    Access 2003: import csv fails as csv is still open

    Hi,

    New member, so allow me to introduce myself before throwing my problem at you. I have been working with Access since version 1, in a government, forest research setting, and developed a fairly complex database for research data. Part of this development is an "Importer", which takes bulk data, renames fields, converts values and then distributes the data to multiple tables.
    I am now in the process of fine-tuning a CSV-format import, but seem to have run into a tiny little snag. The snag: I cannot import a temporary copy of the data CSV, because it was created just prior to the step to import it and is still open. The solution is probably very simple, but it evades me.

    The following code takes mstrFileName, strips the first row, copies the remaining data to a temp file, then imports the temp file:
    '================================================= ===
    Dim fInput
    Dim fOutput
    Dim fs
    Dim sline As String
    Dim strTempTable As String

    strTempTable = "temp.csv"
    Set fs = CreateObject("Scripting.filesystemobject")
    Set fInput = fs.opentextfile(mstrFileName) ' mstrFileName is previously defined object name for the original data CSV to be imported
    Set fOutput = fs.createtextfile(strTempTable)
    sline = fInput.readline ' skip the first line, as it contains field names (not needed)
    Do While fInput.atendofstream <> True
    sline = fInput.readline
    fOutput.writeline sline


    Loop

    ' HERE I NEED to CLOSE the temp csv file before the next step - open doc prevents import

    ' this next step imports the temp.csv - this works great if temp.csv already exists and I skip the code above
    DoCmd.TransferText acImportDelim, "", strTable, strTempTable, False, ""
    '================================================= ===

    Any suggestions would be welcome!
    Thanks,
    Frank :-)

  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
    Review http://www.ozgrid.com/forum/showthread.php?t=53975

    fInput.Close
    fOutput.Close
    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
    vanthien is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Jan 2013
    Posts
    21

    thanks

    as i suspected - amazingly simple. I think i need a holiday.
    Thanks very much June7.
    Frank :-)

  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
    Or you had too much holiday!

    Glad it is working.
    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.

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

Similar Threads

  1. Access fails to open Outlook
    By acessor in forum Access
    Replies: 4
    Last Post: 12-17-2012, 09:39 PM
  2. Access 2003: Import Specification
    By compooper in forum Import/Export Data
    Replies: 2
    Last Post: 08-23-2011, 01:58 PM
  3. import excel file to access 2003 yes, access 2007 no
    By stapik in forum Import/Export Data
    Replies: 9
    Last Post: 07-27-2011, 07:09 AM
  4. Access 2003: Import & Append New data
    By compooper in forum Programming
    Replies: 2
    Last Post: 06-22-2011, 08:44 AM
  5. Import in Access (2003)
    By Claude in forum Programming
    Replies: 2
    Last Post: 06-18-2009, 12:49 AM

Tags for this Thread

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