imperator
Archaeologist etc.
- Local time
- Today, 15:26
- Joined
- Feb 28, 2004
- Messages
- 38
Hi All
Below is a click event which sends the data in a query to Outlook and emails it. It works a charm though I'm sure it lacks programming finesse as I am a novice, but books and the web have got me this far.
My question is this: the click event is on a form showing one record, how can I get this code to send the current record to email? At the moment it just sends the first.
Please excuse all the strMessage variables but I've structured the code to mimic the structure of the email for ease of viewing.
The query ID field is called Bookings_ID and the textbox on the form is called txtBooksing_ID. If I was sending this to a report then I probably could achieve this but as it is going straight into an email I'm stumped.
Private Sub cmdSendEmail_Click()
On Error GoTo Err_cmdSendEmail_Click
Dim db As Database
Dim recBookingQry As Recordset
Dim objOutlook As New Outlook.Application
Dim objMessage As MailItem
Dim strMessage As String
Dim strSQL As String
Dim datNow As Date
Set db = CurrentDb()
Set recBookingQry = db.OpenRecordset("qryLearningBookingEmail")
datNow = Date
strMessage = "Dear " & recBookingQry("ContactName") & vbCrLf & vbCrLf
strMessage = strMessage + "Following our recent correspondence, I am pleased to email to confirm the " & _
"following details for your booking:" & vbCrLf & vbCrLf
strMessage = strMessage + "Name of venue:" & vbTab & vbTab & recBookingQry("Venue") & vbCrLf
strMessage = strMessage + "Workshop: " & vbTab & vbTab & recBookingQry("Workshop") & vbCrLf
strMessage = strMessage + "Charge: " & vbTab & vbTab & Format(recBookingQry("Charge"), "currency") & vbCrLf
strMessage = strMessage + "Date of visit:" & vbTab & vbTab & Format(recBookingQry("BookingDate"), "Long date") & vbCrLf
strMessage = strMessage + "Name of school:" & vbTab & vbTab & recBookingQry("InstitutionName") & vbCrLf
strMessage = strMessage + "Contact name: " & vbTab & vbTab & recBookingQry("ContactName") & vbCrLf
strMessage = strMessage + "Arrival: " & vbTab & vbTab & Format(recBookingQry("ArrivalTime"), "medium time") & vbCrLf
strMessage = strMessage + "Lunch space: " & vbTab & vbTab & recBookingQry("LunchSpace") & vbCrLf
strMessage = strMessage + "Departure: " & vbTab & vbTab & Format(recBookingQry("DepartureTime"), "medium time") & vbCrLf
strMessage = strMessage + "Additional notes:" & vbTab & vbTab & recBookingQry("AdditionalNotes") & vbCrLf & vbCrLf
strMessage = strMessage + "Please check the above details carefully. If you wish to make any amends please contact (0191) " & _
recBookingQry("VenueTel") & " or email " & recBookingQry("OfficerEmail") & " immediately." & _
vbCrLf & vbCrLf
strMessage = strMessage + "This company expect all workshops and sessions to be paid for in advance. " & _
"You can pay in two ways either by invoice or through a Newcastle Journal request. " & _
"Details of how to do this are explained fully on the attached terms and conditions document." & _
vbCrLf & vbCrLf
strMessage = strMessage + "Please read the Terms and Conditions carefully. If you fully understand and agree " & _
"to all of the conditions and wish to confirm your booking please reply to this email, with your completed " & _
"confirmation form, by " & Format(DateAdd("d", 5, datNow), "Long Date") & ". If you fail to do this your slot will be released to allow " & _
"another group to book." & vbCrLf & vbCrLf & "If you have any further questions please do not hesitate in contacting us." & _
vbCrLf & vbCrLf & "We look forward to welcoming you on your visit." & vbCrLf & vbCrLf & "Regards," & vbCrLf & vbCrLf & "The Learning Team"
If Not IsNull(recBookingQry("ContactEmail")) Then
Set objMessage = objOutlook.CreateItem(olMailItem)
With objMessage
.To = recBookingQry("ContactEmail")
.Subject = "Your booking confirmation"
.Body = strMessage
.Importance = olImportanceHigh
.Send
End With
End If
Exit_cmdSendEmail_Click:
Exit Sub
Err_cmdSendEmail_Click:
MsgBox Err.Description
Resume Exit_cmdSendEmail_Click
End Sub
Thanks in advance,
Ray
Below is a click event which sends the data in a query to Outlook and emails it. It works a charm though I'm sure it lacks programming finesse as I am a novice, but books and the web have got me this far.
My question is this: the click event is on a form showing one record, how can I get this code to send the current record to email? At the moment it just sends the first.
Please excuse all the strMessage variables but I've structured the code to mimic the structure of the email for ease of viewing.
The query ID field is called Bookings_ID and the textbox on the form is called txtBooksing_ID. If I was sending this to a report then I probably could achieve this but as it is going straight into an email I'm stumped.
Private Sub cmdSendEmail_Click()
On Error GoTo Err_cmdSendEmail_Click
Dim db As Database
Dim recBookingQry As Recordset
Dim objOutlook As New Outlook.Application
Dim objMessage As MailItem
Dim strMessage As String
Dim strSQL As String
Dim datNow As Date
Set db = CurrentDb()
Set recBookingQry = db.OpenRecordset("qryLearningBookingEmail")
datNow = Date
strMessage = "Dear " & recBookingQry("ContactName") & vbCrLf & vbCrLf
strMessage = strMessage + "Following our recent correspondence, I am pleased to email to confirm the " & _
"following details for your booking:" & vbCrLf & vbCrLf
strMessage = strMessage + "Name of venue:" & vbTab & vbTab & recBookingQry("Venue") & vbCrLf
strMessage = strMessage + "Workshop: " & vbTab & vbTab & recBookingQry("Workshop") & vbCrLf
strMessage = strMessage + "Charge: " & vbTab & vbTab & Format(recBookingQry("Charge"), "currency") & vbCrLf
strMessage = strMessage + "Date of visit:" & vbTab & vbTab & Format(recBookingQry("BookingDate"), "Long date") & vbCrLf
strMessage = strMessage + "Name of school:" & vbTab & vbTab & recBookingQry("InstitutionName") & vbCrLf
strMessage = strMessage + "Contact name: " & vbTab & vbTab & recBookingQry("ContactName") & vbCrLf
strMessage = strMessage + "Arrival: " & vbTab & vbTab & Format(recBookingQry("ArrivalTime"), "medium time") & vbCrLf
strMessage = strMessage + "Lunch space: " & vbTab & vbTab & recBookingQry("LunchSpace") & vbCrLf
strMessage = strMessage + "Departure: " & vbTab & vbTab & Format(recBookingQry("DepartureTime"), "medium time") & vbCrLf
strMessage = strMessage + "Additional notes:" & vbTab & vbTab & recBookingQry("AdditionalNotes") & vbCrLf & vbCrLf
strMessage = strMessage + "Please check the above details carefully. If you wish to make any amends please contact (0191) " & _
recBookingQry("VenueTel") & " or email " & recBookingQry("OfficerEmail") & " immediately." & _
vbCrLf & vbCrLf
strMessage = strMessage + "This company expect all workshops and sessions to be paid for in advance. " & _
"You can pay in two ways either by invoice or through a Newcastle Journal request. " & _
"Details of how to do this are explained fully on the attached terms and conditions document." & _
vbCrLf & vbCrLf
strMessage = strMessage + "Please read the Terms and Conditions carefully. If you fully understand and agree " & _
"to all of the conditions and wish to confirm your booking please reply to this email, with your completed " & _
"confirmation form, by " & Format(DateAdd("d", 5, datNow), "Long Date") & ". If you fail to do this your slot will be released to allow " & _
"another group to book." & vbCrLf & vbCrLf & "If you have any further questions please do not hesitate in contacting us." & _
vbCrLf & vbCrLf & "We look forward to welcoming you on your visit." & vbCrLf & vbCrLf & "Regards," & vbCrLf & vbCrLf & "The Learning Team"
If Not IsNull(recBookingQry("ContactEmail")) Then
Set objMessage = objOutlook.CreateItem(olMailItem)
With objMessage
.To = recBookingQry("ContactEmail")
.Subject = "Your booking confirmation"
.Body = strMessage
.Importance = olImportanceHigh
.Send
End With
End If
Exit_cmdSendEmail_Click:
Exit Sub
Err_cmdSendEmail_Click:
MsgBox Err.Description
Resume Exit_cmdSendEmail_Click
End Sub
Thanks in advance,
Ray
Last edited: