Page 2 of 2 FirstFirst 12
Results 16 to 25 of 25
  1. #16
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    If the folder doesn't already exist, need to create it first.

    MyPath = "C:\TestFolder\" & Me.Client_Name


    If Dir(MyPath)="" Then
    MkDir(MyPath)
    End If
    MyFilename = Format(Me.Job_Date, "yyyy-ddmm") & "_" & Now() & ".pdf"
    DoCmd.OutputTo acOutputReport, , acFormatPDF, MyPath & "\" & MyFilename
    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.

  2. #17
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by agure View Post
    ...I'm just wondering now how can I make it so it doesn't overwrite files with the same name how can i successfully add the time function to the filename to do this?...
    You could incorprate a string variable that has a timestamp. Here is one example.

    dim strTimeStamp as string
    strTimeStamp = Format(Now(), "mmddyyhhss")

    Sometimes I want to be able to read the timestamp

    strTimeStamp = Format(Now(), "mm_dd_yy_hh_ss")

    With that you can concatenate strTimeStamp.

  3. #18
    agure is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Feb 2014
    Posts
    30
    Quote Originally Posted by June7 View Post
    If the folder doesn't already exist, need to create it first.

    MyPath = "C:\TestFolder\" & Me.Client_Name
    If Dir(MyPath)="" Then
    MkDir(MyPath)
    End If
    MyFilename = Format(Me.Job_Date, "yyyy-ddmm") & "_" & Now() & ".pdf"
    DoCmd.OutputTo acOutputReport, , acFormatPDF, MyPath & "\" & MyFilename
    This Worked the first time but the second time I run the exact same invoice it gives me a Path/File access error

  4. #19
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Post the code you used.

  5. #20
    agure is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Feb 2014
    Posts
    30
    Quote Originally Posted by ItsMe View Post
    Post the code you used.
    This worked well the first time when im creating a folder for each Client Name but I think there is a problem with the IF statement

    I also tried it exactly how you had it written

    Dim MyFilter As String
    Dim MyPath As String
    Dim MyFilename As String
    Dim strTimeStamp As String


    MyFilter = "[Invoice#] = '" & [Forms]![Job List (New Job) Form]![Invoice#] & "'"




    MyPath = "C:\TestFolder\" & Me.Client_Name
    If Dir(MyPath) = "" Then
    MkDir (MyPath)
    End If


    strTimeStamp = Format(Now(), "mm_dd_yyyy___@hh_mm")




    MyFilename = "Invoice#" & Me.Invoice_NO_ & "_" & strTimeStamp & ".pdf"




    Debug.Print MyPath
    Debug.Print MyFilename

    DoCmd.OpenReport "Final Invoice Report", acViewPreview, , MyFilter
    DoCmd.OutputTo acOutputReport, "Final Invoice Report", acFormatPDF, MyPath & "\" & MyFilename, True
    DoCmd.Close acReport, "Final Invoice Report"

  6. #21
    agure is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Feb 2014
    Posts
    30
    Quote Originally Posted by ItsMe View Post
    You could incorprate a string variable that has a timestamp. Here is one example.

    dim strTimeStamp as string
    strTimeStamp = Format(Now(), "mmddyyhhss")

    Sometimes I want to be able to read the timestamp

    strTimeStamp = Format(Now(), "mm_dd_yy_hh_ss")

    With that you can concatenate strTimeStamp.
    This string worked really well thank you. !

  7. #22
    agure is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Feb 2014
    Posts
    30
    Now my final concern

    Code:
    MyPath = "C:\TestFolder\" & Me.Client_Name
    If Dir(MyPath) = "" Then
    MkDir (MyPath)
    End If
    This works only the first time I execute for a new client name so i get the new folder. The second time i execute this I receive an error at MkDir(MyPath) any help guys? It is running the If statement when I don't want it to because the folder has already been created.

  8. #23
    agure is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Feb 2014
    Posts
    30
    Instead of :

    Code:
    MyPath = "C:\TestFolder\" & Me.Client_Name
    If Dir(MyPath) = "" Then
    MkDir (MyPath)
    End If
    I used:

    Code:
    On Error Resume NextMkDir MyPath
    On Error GoTo 0
    My final Code

    Code:
    Private Sub Command72_Click() 
    Dim MyFilter As String
    Dim MyPath As String
    Dim MyFilename As String
    Dim strTimeStamp As String
    
    
    MyFilter = "[Invoice#] = '" & [Forms]![Job List (New Job) Form]![Invoice#] & "'"
    
    
    
    
    MyPath = "C:\TestFolder\" & Me.Client_Name
    
    
    On Error Resume Next
    MkDir MyPath
    On Error GoTo 0
    
    
    strTimeStamp = Format(Now(), "mm_dd_yyyy___@hh_mm")
    
    
    
    
    MyFilename = "Invoice#" & Me.Invoice_NO_ & "_" & strTimeStamp & ".pdf"
    
    
    
    
    Debug.Print MyPath
    Debug.Print MyFilename
                    
    DoCmd.OpenReport "Final Invoice Report", acViewPreview, , MyFilter
    DoCmd.OutputTo acOutputReport, "Final Invoice Report", acFormatPDF, MyPath & "\" & MyFilename, True
    DoCmd.Close acReport, "Final Invoice Report"
    
    
    
    
    End Sub

    Thank you everyone for your help, I used bits and pieces from everyone and got exactly what I needed, thanks alot !!!!

  9. #24
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    You can do your directory validation like this.

    If Dir(MyPath, vbDirectory) = "" Then
    MkDir (MyPath)
    End If

    I had to look at some of my code snippits...

  10. #25
    agure is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Feb 2014
    Posts
    30
    Quote Originally Posted by ItsMe View Post
    You can do your directory validation like this.

    If Dir(MyPath, vbDirectory) = "" Then
    MkDir (MyPath)
    End If

    I had to look at some of my code snippits...
    Thanks for looking back, I tried this one too works just as good. Gotta love VBA more than one way to do stuff lol.

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

Similar Threads

  1. command button to export to excel
    By jains in forum Forms
    Replies: 5
    Last Post: 06-30-2015, 06:27 PM
  2. Replies: 2
    Last Post: 01-29-2013, 07:01 PM
  3. Export to HTML Button on Form
    By iProRyan in forum Forms
    Replies: 2
    Last Post: 04-26-2012, 11:41 AM
  4. Export to excel on button click
    By Jim.H. in forum Access
    Replies: 2
    Last Post: 01-29-2012, 12:16 PM
  5. Replies: 0
    Last Post: 03-13-2011, 03:09 PM

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