Hello, first post from an access rookie who is desperately trying to cobble this together.
I am trying to use VB to create an e m a i l that sends via outlook and passes the value from an sql statement into the body.
I'm working on a local database with 2 tables named: businesslist and staff
What i am attempting to do is return a staff name into the body of the e m a i l where the staff initials have been selected from a combo box on a form, the staff initials have a unique key number which i have successfully pulled into the sql but for some reason when i go to include the string into the body it prints the statement and not the value i desire.
Any help would be greatly appreciated as the code below has taken 3 days to mash together using various tips i've gleaned from this forum.
(have had to add spaces to the word email as it think i'm including an address and my post count is currently 0)
Code is as follows:
Private Sub sendit_Click()
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)
Dim Db As DAO.Database
Dim Rcs As DAO.Recordset
Set Db = CurrentDb
Set Rcs = CurrentDb.OpenRecordset("select * from staff")
Dim mymsg As String
Dim StrSql As String
Dim strStaff As String
strStaff = Me.StaffSelect.Value
StrSql = "SELECT staffname FROM staff where staff.staffkey=" & strStaff & ";"
With objEmail
.To = Me![e m a i l obtained]
.Subject = "E m a i l Subject Hard Coded"
mymsg = "Hello "
mymsg = mymsg & vbCrLf
.Body = mymsg & StrSql
.Display
End With
Exit_Here:
Set objOutlook = Nothing
Exit Sub
Error_Handler:
MsgBox Err & ": " & Err.Description
Resume Exit_Here
End Sub
Many thanks in advance!
I am trying to use VB to create an e m a i l that sends via outlook and passes the value from an sql statement into the body.
I'm working on a local database with 2 tables named: businesslist and staff
What i am attempting to do is return a staff name into the body of the e m a i l where the staff initials have been selected from a combo box on a form, the staff initials have a unique key number which i have successfully pulled into the sql but for some reason when i go to include the string into the body it prints the statement and not the value i desire.
Any help would be greatly appreciated as the code below has taken 3 days to mash together using various tips i've gleaned from this forum.
(have had to add spaces to the word email as it think i'm including an address and my post count is currently 0)
Code is as follows:
Private Sub sendit_Click()
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)
Dim Db As DAO.Database
Dim Rcs As DAO.Recordset
Set Db = CurrentDb
Set Rcs = CurrentDb.OpenRecordset("select * from staff")
Dim mymsg As String
Dim StrSql As String
Dim strStaff As String
strStaff = Me.StaffSelect.Value
StrSql = "SELECT staffname FROM staff where staff.staffkey=" & strStaff & ";"
With objEmail
.To = Me![e m a i l obtained]
.Subject = "E m a i l Subject Hard Coded"
mymsg = "Hello "
mymsg = mymsg & vbCrLf
.Body = mymsg & StrSql
.Display
End With
Exit_Here:
Set objOutlook = Nothing
Exit Sub
Error_Handler:
MsgBox Err & ": " & Err.Description
Resume Exit_Here
End Sub
Many thanks in advance!