Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send Email error and Run SQL error

Status
Not open for further replies.

bhujanga

Programmer
Oct 18, 2007
181
US
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.

So 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. 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 String
strSQL1 = "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
 


hi,

Try posting in forum705.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top