I am trying to be able to select multiple values in two listboxes and assign to two separate variables. I want to then take those variables containing the selections and generate an email with the variable contents populating the "TO" field in an outlook email. Right now I am getting a Run-Time Error 94 - Invalid Use of Null.
Thanks for all your help!
Dim EAddress, MAddress As String
Public Sub UserForm_Initialize()
Emailfrm.EmpEmaillb.RowSource = "Searched_Employee_Email"
Emailfrm.ManagerEmaillb.RowSource = "Searched_Manager_Email"
End Sub
Public Sub Email_Click()
Dim OLobjMsg, NewMsg As Object
EAddress = Emailfrm.EmpEmaillb.Value
MAddress = Emailfrm.ManagerEmaillb.Value
Set objMsg = CreateObject("Outlook.Application")
objMsg.Session.Logon
Set NewMsg = objMsg.CreateItem(0)
With NewMsg
.To = EAddress & MAddress
.Subject = "BT Employee Database Inquiry Email"
'.Body = "Have a great weekend!"
End With
Unload Me
NewMsg.Display
End Sub
Asuming that your listboxes contain valid email addresses, I propose to
ListBox1.MultiSelect = fmMultiSelectMulti
_
Private Sub CommandButton1_Click()
Dim LBCnt As Integer, AllAddr As String
AllAddr = ""
For LBCnt = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(LBCnt) Then
If AllAddr = "" Then
AllAddr = ListBox1.List(LBCnt)
Else
AllAddr = AllAddr & ";" & ListBox1.List(LBCnt)
End If
End If
Next LBCnt
Debug.Print AllAddr
End Sub