Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 417
  • Last Modified:

how to show a copying dialog box when copying files in access vba

I have the following problem.

I copy some folders from location A to Location B through a vba code. When Files are big it takes time. All user see is hour glass , can I show some kind of status bar , or time remaining to finish copying?

My code is below:

Sub Copy_Development_Folder_Working_Docs()


    FromPath = DriveLetter & "2077\" & DEVNUMBER 'The folder to copy
    ToPath = DriveLetter & [Forms]![frm_log_in]![TXT_YEAR] & "\" & Me.Number & "\" & "docs" & "\" & DEVNUMBER & "\" 'The folder to paste

    'If you want to create a backup of your folder every time you run this macro
    'you can create a unique folder with a Date/Time stamp.
    'ToPath = "C:\Users\Ron\" & Format(Now, "yyyy-mm-dd h-mm-ss")

    If Right(FromPath, 1) = "\" Then
        FromPath = Left(FromPath, Len(FromPath) - 1)
    End If

    If Right(ToPath, 1) = "\" Then
        ToPath = Left(ToPath, Len(ToPath) - 1)
    End If

    Set FSO = CreateObject("scripting.filesystemobject")

    If FSO.FolderExists(FromPath) = False Then
        MsgBox FromPath & " doesn't exist"
        Exit Sub
    End If

    FSO.CopyFolder Source:=FromPath, Destination:=ToPath
    MsgBox "You can find the files and subfolders from " & FromPath & " in " & ToPath

End Sub
0
maximyshka
Asked:
maximyshka
  • 3
  • 2
  • 2
  • +1
1 Solution
 
peter57rCommented:
No.

You can only report progress if you have a looping mechanism which you can get into.

In this case you only have one 'copy' command so there is nothing you can do until that command has executed.

You can display a "Copying...." status bar message using a syscmd command but it will be fixed message that you will have to clear when the copy has finished..
0
 
maximyshkaAuthor Commented:
can you provide more info or may be a link where file copy was done through a "looping mechanism?"
0
 
Dale FyeCommented:
The only example I could give of that is when you are copying multiple files.  From one folder to another.  Then, you could create an array of the file names and use the filesystem object to determine the size of those files.  Then, as you loop through the array, as each copy operation is completed, you would provide a status bar that indicates that X% of the total operation has completed.

But I don't think this helps with your single, large file issue.

There might be a way to shell out to the application that is running when you do a Windows file copy operation, but I don't know how to do it.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
peter57rCommented:
Are you saying you are copying several large files?

I thought you meant you were only copying a single file which sometimes was 'big'.

There is an example here of looping through files in a folder using a Dir loop

http://support.microsoft.com/kb/139724
0
 
Jeffrey CoachmanCommented:
What you are asking for here is not really "easy".

fyed and Pete are correct in that you have to have some sort of "Loop"
But you also will probably need to know the *Total* number of files before you start looping...
(To display the correct "Amount" of the progress to display)

For this you may need to *recursively* loop the folder and *all SubFolders*
...Not so easy...

Will you need to be specifying Wildcards as well? (ex.: only .xls files)
...will you need to consider file with extensions longer than 3 characters...?(.accdb)
What about Hidden or read only files?

Will you be wanting to "dynamically" set the number of "Bars" based on the number of files? (7 files=7 bars in one case, ...then 22 bars=22f iles in another)
...or will you have a set  number of bars (ex.  10 or 100) and just perform some "division and rounding"...?

Not really trying to scare you off here, just letting yo know that it may not be what you would call "easy".

;-)

JeffCoachman
0
 
Jeffrey CoachmanCommented:
...also not that many codes to do recursive looping through folders and subfolders:
May not include the files in the Root folder
May not search Sub*Sub* folders...
0
 
maximyshkaAuthor Commented:
if some one interested I found a better solution as I think. I will do the following thing.

1 - I wil create another form, which i will call to become visible once the copy will start
2- on that form I will check size of destination folder + size of folder/file i will copy.
 the total size will control progress loop. On each itteration i will check the size of destination folder against total size. once it is equal I will make that form invisible.
0
 
Jeffrey CoachmanCommented:
FWIW, ...
Many things can throw off your "foldersize" technique...
(Sub Folders, Hidden files, ...etc)

If it were me, I would still count the "files"...

Jeff
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now