Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    manic is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    63

    SAving a file to a folder with the same name as the file.

    I tried posting this question in other places and so far no answers that can help me, so here it goes so far I managed to put this code:

    Private Sub Command17_Click()

    Me.Refresh

    Dim stDocName As String

    stDocName = "admin_rptOperator Log"
    DoCmd.OutputTo acReport, stDocName, acFormatPDF, "L:\Operations\Team Managers\" & DatePart("yyyy", Date_of_Log) & " Operator Log\ " & Employee_Name & ".pdf"

    Exit_Command17_Click:
    Exit Sub


    Err_Command17_Click:
    MsgBox Err.Descriptionq
    Resume Exit_Command17_Click

    End Sub

    I have 1 issue/ 1 questions:

    issue 1- the code works great, it saves the file withthe employee name to the correspondent folder (2012 etc..) issue here is if on my form i input something from this year (2012) it saves it great but it also saves everything from 2011 on the same file (employee_name.pdf with all his records from past and present year) all i want to accomplish is for it to save the files from 2011 on the 2011 folder and 2012 on its folder with the same employee name but different year records.

    questions: is there a way that i can add something to the current code above that will make MS Access create a folder automatically with the employee name and save the employee file inside with his record ( that way seems easy for me because i can have access save the employee record with the file id at the end on its own folder as individual files)
    so far I tried
    Dim STRPATH As String

    STRPATH = "L:\Operations\Team Managers\" & DatePart("yyyy", Date_of_Log) & " Operator Log\ " & Me.Employee_Name

    If Dir(STRPATH, vbDirectory) = "" Then MkDir (STRPATH)

    whic creates the folder with the current employee name but the output file does not save inside that folder. It saves it here "L:\Operations\Team Managers\" & DatePart("yyyy", Date_of_Log) & " Operator Log\


    any help will be appreciated.

  2. #2
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Where's your output statement after the blue code above?

  3. #3
    manic is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    63
    this is where i get stuck , i can't manage to get access to save the file on the newly created folder.
    I wan access to create a folder with the employee name and the file inside, for example : Joe Smith.pdf will go on joe smith folder and John doe will go in john doe folder.
    I have the code as such:


    Private Sub Command17_Click()

    Me.Refresh

    Dim stDocName As String
    Dim STRPATH As String

    STRPATH = "L:\Operations\Team Managers\" & DatePart("yyyy", Date_of_Log) & " Operator Log\ " & Me.Employee_Name
    If Dir(STRPATH, vbDirectory) = "" Then MkDir (STRPATH)


    stDocName = "admin_rptOperator Log"
    DoCmd.OutputTo acReport, stDocName, acFormatPDF, "L:\Operations\Team Managers\" & DatePart("yyyy", Date_of_Log) & " Operator Log\ " & Employee_Name & ".pdf"

    Exit_Command17_Click:
    Exit Sub


    Err_Command17_Click:
    MsgBox Err.Descriptionq
    Resume Exit_Command17_Click

    End Sub

  4. #4
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    You should be using strPath in the Output statement instead of hard-coding the path name

  5. #5
    manic is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    63
    how can i implement this to the code that i already have?

  6. #6
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    DoCmd.OutputTo acReport, stDocName, acFormatPDF, strPath & "\" & Employee_Name & ".pdf"

    I'm not sure that the file name makes sense - don't you want to change it to something more meaningful? Maybe add date of log in format "yyyymmdd" to the employee name?

  7. #7
    manic is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    63
    yes adding a date would be nice. Im very new to all this and I appreciate all the help i can get.

  8. #8
    manic is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    63
    by the way thanks for everything, it works like a charm.
    if you can guide on how to add the date that would me great and thanks again.

  9. #9
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    You're doing great! You already added the date to the folder - see if you can do it for yourself (read no further!!)

    Dim FileName as string
    (now you can make it whatever you want, play with it, before doing the output statement)
    Here's one example:
    FileName=Me.Employee_Name & "_" & Format(Date_Of_Log,"yyyymmdd") & ".pdf"

    Note- you could have used Format(Date_of_Log,"yyyy") instead of DatePart - just the same
    Note - in file and folder names you always want to format dates in the above manner because of the alphabetic sorting of names. Sometimes people make the mistake of putting month first or month name ("Jan") or something and don't realize their mistake until a year later when all of a sudden the files get all jumbled up!

  10. #10
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Oh - strPath & "\" & FileName

  11. #11
    manic is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    63
    I got it! thanks alot you are great, it saves like this doe,john_20120120.
    i learnt something here today hehehe.
    I think i need to work on what information it saves because it saves all his records from 2011 plus 2012.
    but you thought me smething new today, thanks.

  12. #12
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    So what is your stDocName? A query?

  13. #13
    manic is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    63
    stDocName table.

  14. #14
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    The table contains both year's worth of data? You need to filter it somehow, use a query or form or something. You use the date of log - where is this from? Table? Form? In a query you can put make a field for the date on the Employee something like:
    Format(Employee_Date,"yyyy"), then in the criteria line "=Format(Date_Of_Log,"yyyy")
    this will match the years. I'm making all this up but I am unsure where the data is coming from!!

  15. #15
    manic is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    63
    the date of log comes from a table field, all the data that is pull it comes from a table called oplog.

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

Similar Threads

  1. How to copy a file from one folder to another in vba
    By pkstormy in forum Code Repository
    Replies: 2
    Last Post: 09-20-2012, 05:32 PM
  2. folder locked after attaching a file
    By jimg972 in forum Access
    Replies: 0
    Last Post: 05-25-2011, 06:21 PM
  3. Copy file to folder
    By tpcervelo in forum Programming
    Replies: 11
    Last Post: 08-31-2010, 10:01 AM
  4. File size smaller after saving
    By Pilotwings_64 in forum Access
    Replies: 1
    Last Post: 08-20-2010, 06:21 AM
  5. Replies: 0
    Last Post: 09-18-2006, 08:37 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