Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2012-03-23
8
Medium Priority
?
412 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 77

Accepted Solution

by:
peter57r earned 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Starting up a Project
Suggested Courses

721 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