Results 1 to 4 of 4
  1. #1
    M.Enders is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jun 2017
    Posts
    9

    VBA file rename with a date issue

    Hello all,

    I am writing a simple code to allow me to move files and automatically rename them using VBA.

    Currently I am using a date drop down via an ActiveX control, Microsoft Date and time Picker 6.0 (SP6)



    I keep getting a run-time error of, File not found.
    I can only assume this is because the control is showing the date as 2017/06/28 and the slashes are preventing the file from being created/moved.

    does anyone know how I can solve this issue

    The coding is:

    Private Sub Command145_Click()

    Dim FSO As New FileSystemObject
    Dim FolderPath1 As String
    Dim FolderPath2 As String
    Dim Date2 As String

    If FSO.FileExists(Nz(Me.Text2.Value, "")) Then
    FolderPath1 = Me.Text2.Value
    Date2 = Me.DTPicker9
    FolderPath2 = "C:\COPA\Soldier_Records" & Me.Combo131 & "" & Me.Combo134 & "_" & Date2 & ".pdf"

    Name FolderPath1 As FolderPath2

    MsgBox "File Uploaded"

    End If


    End Sub

    Thank you for any help.

    Marty

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Try this change:
    Code:
    Date2 = Format(Me.DTPicker9,"yyyymmdd")

  3. #3
    M.Enders is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jun 2017
    Posts
    9
    Well JoeM,

    Thank you so much

    I feel rather silly that such a simple change corrected the issue, the code that worked is:

    Private Sub Command145_Click()

    Dim FSO As New FileSystemObject
    Dim FolderPath1 As String
    Dim FolderPath2 As String
    Dim Date2 As String

    If FSO.FileExists(Nz(Me.Text2.Value, "")) Then
    FolderPath1 = Me.Text2.Value
    Date2 = Format(Me.DTPicker9, "yyyymmdd")
    FolderPath2 = "C:\COPA\Soldier_Records" & Me.Combo131 & "" & Me.Combo134 & "_" & Date2 & ".pdf"

    Name FolderPath1 As FolderPath2

    MsgBox "File Uploaded"

    End If


    End Sub

  4. #4
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You are welcome. If you want to separate the month, day, year, you could use underscores, i.e.
    Code:
    Date2 = Format(Me.DTPicker9, "yyyy_mm_dd")

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

Similar Threads

  1. Replies: 1
    Last Post: 07-30-2015, 05:52 AM
  2. Replies: 6
    Last Post: 08-16-2014, 11:20 AM
  3. rename a PDF File
    By sdel_nevo in forum Programming
    Replies: 3
    Last Post: 08-21-2013, 12:11 PM
  4. Replies: 4
    Last Post: 10-30-2012, 02:54 PM
  5. Have access rename a .txt file and move it
    By dh010010 in forum Programming
    Replies: 5
    Last Post: 07-22-2010, 10: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