Page 2 of 2 FirstFirst 12
Results 16 to 25 of 25
  1. #16
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641

    If this is in a standard module, it can all be in the same one. I didn't know if you had this in a form module.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  2. #17
    Alonza Malcom is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Sep 2015
    Posts
    13
    Like this? Getting this error when I run the make- table query...


    Compile error:

    Only comments may appear after End sub, End function, or End property


    Option Compare Database
    Option Explicit
    Public strfile As String
    Function DoImportandAppend()
    Public Function GetFileName() As String
    GetFileName = strfile
    End Function
    Dim strPathFile As String
    Dim strfile As String
    Dim strPath As String
    Dim strTable As String
    Dim blnHasFieldNames As Boolean
    ' Change this next line to True if the first row in CSV worksheet
    ' has field names
    blnHasFieldNames = False
    ' Replace C:\Users\u8201332\Desktop\New folder with the new path to the folder that
    ' contains the CSV files
    strPath = "C:\Users\u8201332\Desktop\HRC folder\"
    ' Replace tablename with the real name of the table into which
    ' the data are to be imported
    strfile = Dir(strPath & "*.csv")

    Do While Len(strfile) > 0
    strTable = Left(strfile, Len(strfile) - 4)
    strPathFile = strPath & strfile
    DoCmd.TransferText acImportDelim, , strTable, strPathFile, blnHasFieldNames

    ' Copy imported file to a tempfile, requery to change format and append new data to a
    ' master HRC table


    DoCmd.SetWarnings False
    DoCmd.CopyObject "", "tblhrc", acTable, strTable
    DoCmd.OpenQuery "qryHRCflatfile", acViewNormal, acAdd
    DoCmd.OpenQuery "qryappHRCdata", acViewNormal, acAdd

    ' Uncomment out the next code step if you want to delete the
    ' EXCEL file after it's been imported

    ' Kill strTable
    strfile = Dir()
    Loop

    End Function

  3. #18
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    You put the new function inside the existing one. They have to be separate:

    Public Function Blah
    ...
    End Function

    Public Function Whatever
    ...
    End Function
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #19
    Alonza Malcom is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Sep 2015
    Posts
    13
    Did that...the Sourcefile field is coming in blank...any ideas?

    Option Compare Database
    Public strfile As String
    Public Function GetfileName() As String
    GetfileName = strfile
    End Function

  5. #20
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    You mean in the newly created table? Did you remove

    Dim strfile As String

    from the existing function (remember I said move it)? This would also help:

    http://www.baldyweb.com/OptionExplicit.htm

    You've declared it twice, and the function is now pulling the wrong one.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #21
    Alonza Malcom is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Sep 2015
    Posts
    13
    You're absolutely right!!! Works beautifully...thank you!!!

  7. #22
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #23
    Alonza Malcom is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Sep 2015
    Posts
    13
    Good Morning Paul!

    I have a new request for this procedure (u gotta love it)! Can I include in the import automation a function that un-zips a folder that the .csv files are received in and include the entire path in the imported filename instead of just the filename itself? Thanks!

  9. #24
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    You can unzip; I found this when I first needed it:

    http://www.webr2.com/how-do-i-extrac...ugh-ms-access/
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #25
    Alonza Malcom is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Sep 2015
    Posts
    13
    OK, but I need to include the full path of the file that i'm inporting as the filename...ex: Include "C:\Users\u8201332\Desktop\HRC folder\" into the filename upon import? Thanks

    strPath = "C:\Users\u8201332\Desktop\HRC folder\"
    ' Replace tablename with the real name of the table into which
    ' the data are to be imported
    strfile = Dir(strPath & "*.csv")

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Import(copy) data from another table
    By tazzzz in forum Import/Export Data
    Replies: 16
    Last Post: 09-17-2015, 11:55 AM
  2. Import files into access automation
    By Rob_U in forum Access
    Replies: 15
    Last Post: 04-10-2015, 03:38 AM
  3. Replies: 1
    Last Post: 09-03-2014, 10:48 AM
  4. Updating main table from temp table AND form value
    By shabbaranks in forum Programming
    Replies: 8
    Last Post: 05-01-2013, 07:18 AM
  5. delete temp table
    By slimjen in forum Queries
    Replies: 1
    Last Post: 07-19-2012, 06:35 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