Results 1 to 3 of 3
  1. #1
    crdfox is offline Novice
    Windows 11 Access 2019
    Join Date
    Apr 2023
    Posts
    1

    Exclamation VBA - Filecopy during a loop

    I Find the file i want, but cannot copy it to another folder?

    Can anyone please help

    Regards crdfox
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,860
    Please show the code within code tags using the # button.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    As WGM suggests, you should post the code rather than a pdf or image. Just copy and paste and apply the code tags.

    Code:
    Do While loop V 290423:---------------------------
    Dim Filename As String
    Dim parth As String
    Dim dymy As String
    Dim Dest As String
    
    Dest = "D:\Data\BBO\Test"
    parth = "D:\Data\BBO"
    
    Filename = Dir(parth)
    
    Do While Len(Filename) > 0
    dymy = Mid(Filename, 1, 4)
    
    If dymy = Format(Now(), "mmdd") Then
    
    MsgBox " This is the File " & dymy 
    
    'need file copy function here
    
    End If
    
    MsgBox [dymy]
    
    Filename = Dir
    
    Loop
    
    End Sub
    If there is only one file and you know the name then use fso

    Code:
    Sub CopyMyFile(SourceFile As String, Destination As String)
     
        Dim fso As Object
        Set fso = CreateObject("Scripting.FileSystemObject")
    
    
        If fso.FileExists(SourceFile) Then
            
           ' fso.CopyFile SourceFile, Destination  'if you want to copy to new location
            fso.MoveFile SourceFile, Destination  'if you want to move to new location
        
       else
    
          Msgbox "File Doesn't Exist"
    
        End If
    
    
        Set fso = Nothing
    
    
    End Sub
    In your loop you could use the Name() https://learn.microsoft.com/en-us/of...name-statement
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

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

Similar Threads

  1. FileCopy Question
    By Ellpee in forum Programming
    Replies: 26
    Last Post: 11-16-2021, 12:17 PM
  2. Replies: 2
    Last Post: 10-05-2018, 10:56 AM
  3. Faster way to copy a file than FileCopy()
    By kdbailey in forum Access
    Replies: 10
    Last Post: 10-29-2015, 07:20 AM
  4. FileCopy
    By thescottsman92 in forum Access
    Replies: 1
    Last Post: 09-02-2013, 04:35 PM
  5. FileCopy Funtion
    By dccjr in forum Programming
    Replies: 2
    Last Post: 04-18-2013, 09:04 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