Solved

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

Posted on 2012-03-23
8
384 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
 
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now