Hi there
I need to know how to select multiple list items from a list box. My code below only selects one email address when there's found that more than one ID's is behind schedule...
Private Sub Form_Load()
folder = Dir("c:\LogBook\*.txt") 'variable folder conatins names of files in folder c:\LogBook\ with extension *.txt
While Len(folder) <> 0 'loop while length of folder is 0 which means no file found...
List1.AddItem Left(folder, InStr(folder, ".txt") - 1) 'add file to list, but trim .txt extension..
folder = Dir() 'read again
Wend
End Sub
Private Sub Picture2_Click()
Dim IDs As String
For i = 0 To List1.ListCount - 1 'do loop within all od list1 indexes
If List1.Selected(i) Then 'If checked index is selected then ...
filename = "c:\LogBook\" + List1.List(i) + ".txt" 'Construct filename, add folder and extension
Open filename For Input As #1 'Open file for reading
While Not EOF(1)
Line Input #1, LineA 'Since all dates are same i will read only 1st row
Wend
Close #1 'Close file
If DateDiff("d", CDate(Left(LineA, 10)), Now()) > 2 Then 'If difference between now and readed date is more than 2 days ("d")
''IDs = IDs & "ID " & List1.List(i) & " IDFrom" & CDate(Left(LineA, 10)) & " Now=" & Now() & " Datediff=" & DateDiff("d", CDate(Left(LineA, 10)), Now()) & Chr(13)
IDs = IDs & IIf(Len(IDs) > 0, ",", "") & List1.List(i) 'Add id to listbox. You can construct this info how do you like
End If
End If
Next
MsgBox IDs 'Display ID's
On Error GoTo Err_Email
Dim objOL As Outlook.Application
Dim msg As Outlook.MailItem
Set objOL = New Outlook.Application
Set msg = objOL.CreateItem(olMailItem)
With msg
.To = personel.List(List1.ListIndex)
.Subject = Subject
.Body = Body
.Display
End With
Exit_Email:
Set objOL = Nothing
Exit Sub
Err_Email:
MsgBox "Error #" & Err.Number & ": " & Err.Description
Resume Exit_Email
End Sub