I have a form for processing permit applications. When certain dates or actions are documented in the form, they want to be able to generate a preformatted email based on that particular event. They also want to be able to save a history of the emails that were sent.
So I have a table called "Email Default Templates" that stores Subject Line, CC, and Message Text for the various types of emails. I also have an "Emails" table where I store that information plus the recipient, permit number and date sent for each email that gets sent using this system.
I am putting command buttons next to these fields that say "Send Email" on them. I am using an SQL statement to append a record to "Emails" based on data looked up from the "Email Default Templates" table along with the current date, and information pulled from the form itself. Then I'm using the SendObject command to send the actual email.
The code for one of these buttons is below. The rest would be exactly the same except for the first line.When it gets to the CurrentDBExecute statement I get an error that says "Error in INSERT INTO statement.If I comment that out, then when I get to the SendObject statement I get an error that says 'Microsoft Access can't send this email. I'd appreciate any help with these problems. Thank you.
CODE:
EmailType = "Deficient Application Response" 'This is for looking up the right info in Templates table
PermitNo = Me![PermitNumber]
SendDate = Date
CCs = DLookup("[CC]", "Email Default Templates", "[Origination Key] = '" & EmailType & "'")
SubjectLine = DLookup("[SubjectLine]", "Email Default Templates", "[Origination Key] = '" & EmailType & "'")
Message = DLookup("[Message]", "Email Default Templates", "[Origination Key] = '" & EmailType & "'")
strAddressee= Me![PermitteeName]'Put info in table
Dim strSQL1 As Stringstr
SQL1 = "INSERT INTO [Emails] " & _"(PermitNumber, SendDate, CC, SubjectLine, Message, TO,) " & _"Select PermitNo as EXPR1, SendDate as EXPR2, CCs as EXPR3, SubjectLine as EXPR4, " & _"Message as EXPR5, strAddressee as EXPR6"
CurrentDb.Execute strSQL1, dbFailOnError
DoCmd.SendObject acSendNoObject, , , strAddressee, CCs, , SubjectLine, Message, True
So I have a table called "Email Default Templates" that stores Subject Line, CC, and Message Text for the various types of emails. I also have an "Emails" table where I store that information plus the recipient, permit number and date sent for each email that gets sent using this system.
I am putting command buttons next to these fields that say "Send Email" on them. I am using an SQL statement to append a record to "Emails" based on data looked up from the "Email Default Templates" table along with the current date, and information pulled from the form itself. Then I'm using the SendObject command to send the actual email.
The code for one of these buttons is below. The rest would be exactly the same except for the first line.When it gets to the CurrentDBExecute statement I get an error that says "Error in INSERT INTO statement.If I comment that out, then when I get to the SendObject statement I get an error that says 'Microsoft Access can't send this email. I'd appreciate any help with these problems. Thank you.
CODE:
EmailType = "Deficient Application Response" 'This is for looking up the right info in Templates table
PermitNo = Me![PermitNumber]
SendDate = Date
CCs = DLookup("[CC]", "Email Default Templates", "[Origination Key] = '" & EmailType & "'")
SubjectLine = DLookup("[SubjectLine]", "Email Default Templates", "[Origination Key] = '" & EmailType & "'")
Message = DLookup("[Message]", "Email Default Templates", "[Origination Key] = '" & EmailType & "'")
strAddressee= Me![PermitteeName]'Put info in table
Dim strSQL1 As Stringstr
SQL1 = "INSERT INTO [Emails] " & _"(PermitNumber, SendDate, CC, SubjectLine, Message, TO,) " & _"Select PermitNo as EXPR1, SendDate as EXPR2, CCs as EXPR3, SubjectLine as EXPR4, " & _"Message as EXPR5, strAddressee as EXPR6"
CurrentDb.Execute strSQL1, dbFailOnError
DoCmd.SendObject acSendNoObject, , , strAddressee, CCs, , SubjectLine, Message, True