HadererDirndl
Registered User.
- Local time
- Yesterday, 19:03
- Joined
- Jan 25, 2016
- Messages
- 19
I have a data base from which I can send emails via Outlook, using VBA. One use case is sending meeting invites. The information for the emails – meeting topic, date and location – is stored in tblMeetings. On the form that displays a particular meeting to the user, the user can click a button, and an Outlook email “invite” is generated. The information about the specific meeting is pulled from the currently open record. But, currently, the rest of the email subject and body are hardcoded in the VBA code. Example:
As a next step, I was hoping to expose the email texts to the user as “email templates”, so they can change them without anyone having to go into the code. (I am not talking about Outlook templates. This should all be within Access!)
For this, I thought I could construct a table called tblEmailTemplates, with (for simplicity’s sake) three fields: [EMailPurpose], [EmailSubject], and [EmailBody]. Then in the code, I would refer to those fields as follows:
This works mostly fine (I have not worked out email body formatting) if the subject and body do not need to refer to fields in tblMeetings. So for [EmailSubject]=”Upcoming Meeting”, it works as expected: An email with the subject Upcoming Meeting is generated. However, I have been unable to figure out how to refer to the respective fields from tblMeetings in the fields in tblEMailTemplates, in a way that they are then recognized by the code. The code just returns the content of the field EmailSubject as a string. So if I store the text as
Does anyone know how to store references in a table field that can be accessed with VBA? Is that even possible? (I am a VBA novice.) Thank you!
Code:
.Subject = "Reminder: Upcoming Meeting " & " on " & Me.MeetingDate & " (" & Me.MeetingTopic & ")"
.Body = "Hello staff," & Chr(13) & Chr(13) & "we want to remind you of our upcoming staff meeting:" & Chr(10) & Chr(13) & Me.MeetingTopic & Chr(13) & Me.MeetingDate & " from " & Me.MeetingStartTime & " to " & Me.MeetingEndTime & Chr(13) & "Location: " & Me.MeetingLocation & Chr(13) & Chr(13) & "Thank you!"
.Display
As a next step, I was hoping to expose the email texts to the user as “email templates”, so they can change them without anyone having to go into the code. (I am not talking about Outlook templates. This should all be within Access!)
For this, I thought I could construct a table called tblEmailTemplates, with (for simplicity’s sake) three fields: [EMailPurpose], [EmailSubject], and [EmailBody]. Then in the code, I would refer to those fields as follows:
Code:
.Subject = DLookup("EmailSubject", "tblEMailTemplates", "EmailPurpose = 'MeetingInvite'")
.Body = DLookup("EmailBody", "tblEMailTemplates", "EmailPurpose = 'MeetingInvite'")
This works mostly fine (I have not worked out email body formatting) if the subject and body do not need to refer to fields in tblMeetings. So for [EmailSubject]=”Upcoming Meeting”, it works as expected: An email with the subject Upcoming Meeting is generated. However, I have been unable to figure out how to refer to the respective fields from tblMeetings in the fields in tblEMailTemplates, in a way that they are then recognized by the code. The code just returns the content of the field EmailSubject as a string. So if I store the text as
"Reminder: Upcoming Meeting " & " on " & Me.MeetingDate & " (" & Me.MeetingTopic & ")"
that’s literally what it will output into the email’s subject line, quotation marks and all.Does anyone know how to store references in a table field that can be accessed with VBA? Is that even possible? (I am a VBA novice.) Thank you!