Solved

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

Posted on 2012-03-23
8
387 Views
Last Modified: 2012-03-30
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
Comment
Question by:maximyshka
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 37757651
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
 

Author Comment

by:maximyshka
ID: 37757736
can you provide more info or may be a link where file copy was done through a "looping mechanism?"
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 37757806
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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 77

Accepted Solution

by:
peter57r earned 500 total points
ID: 37757829
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
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37758269
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
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37758387
...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
 

Author Comment

by:maximyshka
ID: 37788168
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
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37788452
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about problems I had with the new location API and permissions in Marshmallow
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question