S
sexton75 via AccessMonster.com
Good morning,
Using VBA, I created code that will query a list of emails that need to be
sent out automatically. That worked fine and did what I needed it to do.
I wanted to take it a step further and use an append query to record the
email event in the activities table. Unfortunately, I cant get it to work.
The error I get is that it pops up a box requesting the ticketid and
contactid when the append query runs. I am at a loss, so any help would be
great! Here is what I have:
Dim MyDB As Database, RS As Recordset
Dim strBody As String, lngCount As Long, lngRSCount As Long
Set MyDB = DBEngine.Workspaces(0).Databases(0)
Set RS = MyDB.OpenRecordset("Qry_ErrorEmail")
lngRSCount = RS.RecordCount
strto = RS!Email
strdate = RS!DateIn
strtransactiono = RS!ProcessingID_pk
strclientname = RS!ClientName
strregistration = RS!RegistrationCategory
strerrorno = RS!TicketID_pk
strticket = RS!Ticket
strcontact = RS!ContactID_fk
Dim strappendactivity As String
strappendactivity = "INSERT INTO Tbl_Activities ( TicketID_fk, [Date], [Time],
ActivityType_fk, ActivityCategory_fk, ActivityGroup_fk, ActivityStatus_fk,
ContactID_pk, Notes ) " & _
"SELECT [Qry_ErrorEmail]![ticketid_pk] AS TicketID, Date() AS Adate, Time()
AS ATime, 5 AS ActivityType, 2 AS ActivityCategory, 4 AS ActivityGroup, 4 AS
Status, [Qry_ErrorEmail]![contactid_fk] AS contactid, ""<SYSTEM GENERATED
NOTE>: Initial E-Mail Notification Sent"" AS Notes; "
If lngRSCount = 0 Then
MsgBox "No Errors were found.", vbInformation
Else
RS.MoveLast
RS.MoveFirst
Do Until RS.EOF
lngCount = lngCount + 1
DoCmd.SendObject acSendNoObject, , , strto, , , "Order Error Notification",
"You are receiving this message because we need further information on
business you submitted. Please contact our office at your earliest
convenience!", False
DoCmd.SetWarnings False
DoCmd.RunSQL strappendactivity
DoCmd.SetWarnings True
RS.MoveNext
Loop
End If
RS.Close
MyDB.Close
Set RS = Nothing
Set MyDB = Nothing
Close
MsgBox "Done sending Order Errors. ", vbInformation, "Done"
Exit Sub
End Sub
Using VBA, I created code that will query a list of emails that need to be
sent out automatically. That worked fine and did what I needed it to do.
I wanted to take it a step further and use an append query to record the
email event in the activities table. Unfortunately, I cant get it to work.
The error I get is that it pops up a box requesting the ticketid and
contactid when the append query runs. I am at a loss, so any help would be
great! Here is what I have:
Dim MyDB As Database, RS As Recordset
Dim strBody As String, lngCount As Long, lngRSCount As Long
Set MyDB = DBEngine.Workspaces(0).Databases(0)
Set RS = MyDB.OpenRecordset("Qry_ErrorEmail")
lngRSCount = RS.RecordCount
strto = RS!Email
strdate = RS!DateIn
strtransactiono = RS!ProcessingID_pk
strclientname = RS!ClientName
strregistration = RS!RegistrationCategory
strerrorno = RS!TicketID_pk
strticket = RS!Ticket
strcontact = RS!ContactID_fk
Dim strappendactivity As String
strappendactivity = "INSERT INTO Tbl_Activities ( TicketID_fk, [Date], [Time],
ActivityType_fk, ActivityCategory_fk, ActivityGroup_fk, ActivityStatus_fk,
ContactID_pk, Notes ) " & _
"SELECT [Qry_ErrorEmail]![ticketid_pk] AS TicketID, Date() AS Adate, Time()
AS ATime, 5 AS ActivityType, 2 AS ActivityCategory, 4 AS ActivityGroup, 4 AS
Status, [Qry_ErrorEmail]![contactid_fk] AS contactid, ""<SYSTEM GENERATED
NOTE>: Initial E-Mail Notification Sent"" AS Notes; "
If lngRSCount = 0 Then
MsgBox "No Errors were found.", vbInformation
Else
RS.MoveLast
RS.MoveFirst
Do Until RS.EOF
lngCount = lngCount + 1
DoCmd.SendObject acSendNoObject, , , strto, , , "Order Error Notification",
"You are receiving this message because we need further information on
business you submitted. Please contact our office at your earliest
convenience!", False
DoCmd.SetWarnings False
DoCmd.RunSQL strappendactivity
DoCmd.SetWarnings True
RS.MoveNext
Loop
End If
RS.Close
MyDB.Close
Set RS = Nothing
Set MyDB = Nothing
Close
MsgBox "Done sending Order Errors. ", vbInformation, "Done"
Exit Sub
End Sub