I've checked the forum for this particular issue and I found an example of what I want to do, but I can't make sense out of it and I can't get my code to work. Can somebody please help me?
I have a userform with a button on it that loops through rows on a spread sheet. then it takes the information from the cell and set it to a variable. then I call a function called sendNotice that sends an email with the variable "myName" in the body. I don't know how to pass the variable to my function. Here's my code that doesn't work and for the sake of shortening the code I didn't include all the declared variables.
Private Sub cmdUpdateDB_Click()
dim myName as string
lastrow = Cells(Rows.Count, "b").End(xlUp).Row
myName = ""
For I = 20 To lastrow
'Get Fields
ctrfname = Cells(I, "b").Value
ctrlname = Cells(I, "f").Value
ctrmid = Cells(I, "e").Value
ctrSSN = Cells(I, "i").Value
ctrDOB = Cells(I, "j").Value
ctrVendor = Cells(I, "k").Value
If myName = "" Then
myName = "* " & ctrfname & Chr(32) & ctrlname & ", " & ctrVendor
Else
myName = myName & Chr(13) & "* " & ctrfname & Chr(32) & ctrlname & ", " & ctrVendor
End If
Next
Call SendNotice
End Sub
--------------------------------------------------------------------
Function SendNotice(myName as string)
Set OLF = GetObject("", _
"Outlook.Application").GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
Set olMailItem = OLF.Items.Add ' creates a new e-mail message
With olMailItem
.Subject = "EXCEPTION REQUEST FOR TEMPORARY FACILITIES ACCESS (" & exceptapprvd & ")" ' message subject
Set ToContact = .Recipients.Add("somename@fanniemae.com") ' add a recipient
Set ToContact = .Recipients.Add("somename@fanniemae.com")
Set ToContact = .Recipients.Add("" & mgruserid & "")
ToContact.Type = olCC ' set latest recipient as CC
Set ToContact = .Recipients.Add("" & vpUserID & "")
ToContact.Type = olCC ' set latest recipient as CC
.Body = myName
.Display 'Send ' sends the e-mail message (puts it in the Outbox)
End With
ENd Function