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

    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
    Swansea,South Wales,UK
    Please show the code within code tags using the # button.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting:
    Debugging Access:

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

    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
    End Sub
    If there is only one file and you know the name then use fso

    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
          Msgbox "File Doesn't Exist"
        End If
        Set fso = Nothing
    End Sub
    In your loop you could use the Name()
    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