I've managed to create a button and get it to send an email through outlook for one specified user, but I don't know understand how to get it to choose the user of the form I'm currently on. I've done some research and it appears the DLookup is the way to do this. I don't understand how to reference my table (Person). I've seen examples that keep using Me.cboAssign, but I don't know what this means.
Could someone explain this to me and maybe help me out a little?
Here's the code I'm stuck on:
Private Sub Command69_Click() 'send email
On Error GoTo Err_Command69_Click
Dim stWhere As String 'criteria for a DLookup
Dim varTo As Variant 'Address for SendObject (who I am sending the e-mail to)
Dim strWho As String 'ref to Personnel table
Dim strText As String 'body of the email
Dim strSubj As String 'subject of the email
stWho = " " 'not sure what belongs here to use below
stWhere = "Personnel.UserID = " & "'" & stWho & "'"
varTo = DLookup("", "Person", stWhere)
strSubj = "Email sent"
strText = "Dear User" & " "
DoCmd.SendObject acSendNoObject, , , varTo, , , strSubj, strText, -1
Exit_Command69_Click:
Exit Sub
Err_Command69_Click:
MsgBox Err.Description
Resume Exit_Command69_Click
End Sub
Could someone explain this to me and maybe help me out a little?
Here's the code I'm stuck on:
Private Sub Command69_Click() 'send email
On Error GoTo Err_Command69_Click
Dim stWhere As String 'criteria for a DLookup
Dim varTo As Variant 'Address for SendObject (who I am sending the e-mail to)
Dim strWho As String 'ref to Personnel table
Dim strText As String 'body of the email
Dim strSubj As String 'subject of the email
stWho = " " 'not sure what belongs here to use below
stWhere = "Personnel.UserID = " & "'" & stWho & "'"
varTo = DLookup("", "Person", stWhere)
strSubj = "Email sent"
strText = "Dear User" & " "
DoCmd.SendObject acSendNoObject, , , varTo, , , strSubj, strText, -1
Exit_Command69_Click:
Exit Sub
Err_Command69_Click:
MsgBox Err.Description
Resume Exit_Command69_Click
End Sub