Solved

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

Posted on 2012-03-23
8
401 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 48

Expert Comment

by:Dale Fye
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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

617 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