Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Store values for a Msgbox? 1

Status
Not open for further replies.

Clarinet

Technical User
Mar 21, 2005
20
US
I have a simple app that copies files from one location to another. The file names to be copied are listed in an array (myList) and error trapping is in place that generates a message box EACH time a file is not found.

Question, instead of a message box for every file not found, is it possible to store the missing files somehow and generate just one message box at the end that displays all of the missing files?

The code that produces multiple message boxes:

For I = LBound(myList) To UBound(myList)
On Error GoTo Err_cmdCopyFiles_Click
FileCopy strCopyFrom & myList(I), strDestinationFile & myList(I)

Next I

Err_cmdCopyFiles_Click:

Select Case Err.Number

Case 53
MsgBox myList(I) & " was not found in:" & vbCrLf & _
strCopyFrom, vbInformation, "File Copy Error"
Resume Next
Case 76
MsgBox "Destination file path " & strDestinationFile & _
" not found.", vbInformation, "File Copy Error"
Exit_cmdCopyFiles_Click:
Exit Sub
End Select

Thank you in advance for your help!


 
You could create a string variable, and populate it with missing file name & vbCrLf.

Each time a new missing file comes up, append new file name & vbCrLf.

Use this variable in your message box and you will get a vertical listing of all missing files.

Hope this helps,

Alex

A wise man once said
"The only thing normal about database guys is their tables".
 
Alex,
Thank you for your reply. Could you provide an example of populating a string variable and appending with each new file name?

I'm not sure of the code and where to place it.

Thanks again.
 
It would be something like this:

Code:
[b]Dim testStr as String[/b]

'...other code before loop

[b]testStr = ""[/b]

For I = LBound(myList) To UBound(myList)
On Error GoTo Err_cmdCopyFiles_Click
   FileCopy strCopyFrom & myList(I), strDestinationFile & myList(I)
    
Next I


[b]MsgBox "The Following Files were not found in " & _
strCopyFrom & ":" & vbCrLf & testStr, _
vbInformation, "File Copy Error"[/b]


Err_cmdCopyFiles_Click:

    Select Case Err.Number
    
    Case 53
        [b]testStr = testStr & myList(i) & " " & Err.Number & vbCrLf[/b]
        Resume Next
    Case 76
        [b]testStr = testStr & myList(i) & " " & Err.Number & vbCrLf[/b]
    End Select

Exit_cmdCopyFiles_Click:
       Exit Sub

Basically you append to your string rather than displaying a message box in case of the two error types, and then show it all at the end of your loop in a message box.

I have attempted to include error type with each file name, as that may be of use for you.

Hope this helps,

Alex

A wise man once said
"The only thing normal about database guys is their tables".
 
Alex,
Perfect - code works great. Thank you so much and have a star for your quick and accurate responses today.
 
I understand that Alex gave you what works well for you but you could also consider a user defined type w/ 2parts...

FileName and error

dim your array of type "Your Type" and process your files. As it fails set the error part of the current item to True.

When complete you can loop through the array printing all those with error. Alex's works just fine and that is what you asked for (I am not looking to step on toes here) but this type of array may help you in other output types like printing to a file etc.

Andy Baldwin

"Testing is the most overlooked programming language on the books!"

Ask a great question, get a great answer. Ask a vague question, get a vague answer.
Find out how to get great answers FAQ219-2884.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top