Solved

Displaying an Array in a MsgBox

Posted on 2006-07-07
3
366 Views
Last Modified: 2010-04-08
I have a text file which has each persons name and their email, (eg. John Smith=john.smith@abc.com) and i have code which tests to see whether a pdf pay slip exists (eg.John Smith Pay Slip.pdf). What i want to do is display the values of the array of people who do not have a pay slip for the particlaur period, into a msgbox and the same for the ones who do. (lines ****). Any ideas of how to even assign these values to 2 different arrays which could be displayed?




For intCounter = LBound(arrFiles) To UBound(arrFiles)
            strFilename = "H:\Files\" & arrFiles(intCounter) & " " & "Pay Slip.pdf"
            If objFSO.FileExists(strFilename) Then
 *****               'store values of names who DO have files
                Set olkMessage = Application.CreateItem(olMailItem)
                With olkMessage
                    .Subject = "Pay Slip" & " for " & Mid(strFolder, 4, Len(strFolder) - 3)
                    .Body = "Here's your pay slip."
                    'Change the file name and path on the following line as desired
                    .Attachments.Add strFilename
                    .Recipients.Add arrAddresses(intCounter)
                    .Send
                End With
            Else
 *****               'store names of files which DO NOT exist
                End If
        Next
0
Comment
Question by:james_daley
  • 2
3 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
Comment Utility
Hi james_daley,

Rather than use an array it'd be far simpler to store them in two string variables.  Something like this:

    Dim strNamesWithSlips As String, _
    strnamesWithoutSlips As String
    For intCounter = LBound(arrFiles) To UBound(arrFiles)
            strFilename = "H:\Files\" & arrFiles(intCounter) & " " & "Pay Slip.pdf"
            If objFSO.FileExists(strFilename) Then
                strNamesWithSlips = strNamesWithSlips & arrFiles(intCounter) & vbCrLf
                Set olkMessage = Application.CreateItem(olMailItem)
                With olkMessage
                    .Subject = "Pay Slip" & " for " & Mid(strFolder, 4, Len(strFolder) - 3)
                    .Body = "Here's your pay slip."
                    'Change the file name and path on the following line as desired
                    .Attachments.Add strFilename
                    .Recipients.Add arrAddresses(intCounter)
                    .Send
                End With
            Else
                strNamesWithoutSlips = strNamesWithoutSlips & arrFiles(intCounter) & vbCrLf
            End If
    Next
    MsgBox "The following staff have pay slips: " & strNamesWithSlips & "The following staff do not have payslips: " & strNamesWithoutSlips

Cheers!
0
 
LVL 1

Author Comment

by:james_daley
Comment Utility
Thanks very much. Once again you've come to the rescue!
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
You're welcome.  Always happy to be able to help out.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Join & Write a Comment

Learn more about how the humble email signature can be used as more than just an electronic business card. When used correctly, a signature can easily be tailored for different purposes by different departments within an organization.
Use email signature images to promote corporate certifications and industry awards.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

728 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

11 Experts available now in Live!

Get 1:1 Help Now