G
Gary Dolliver
Hi all,
thanks to help from Daniel P, I got the ground work for creating a loop
statement to be used to go through a select query and send an email to each
record. I have added code to set up the variables (and also believe this is
where the problem is) and here is the following code:
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("Ship_Confirmation_Email")
If rst.RecordCount > 0 Then 'ensure there is data
rst.MoveFirst 'goto the 1st recordset
Do Until rst.EOF 'End of file
Dim sAddress As String
Dim STD As String
Dim TID As String
Dim ST As String
sAddress = DLookup("ShipTo_Email", "Ship_Confirmation_Email")
STD = DLookup("Ship_Type_Description", "Ship_Confirmation_Email")
TID = DLookup("Tracking_ID", "Ship_Confirmation_Email")
ST = DLookup("Ship_Times", "Ship_Confirmation_Email")
DoCmd.SendObject acSendNoObject, , , sAddress, , , "Order Shipment
Notification - Creations by You", "This email is to serve notice that your
Creations by You order has shipped!" _
& vbNewLine _
& vbNewLine _
& "It was sent via " + STD + " " + TID + " and will take
approximately " + ST + " for delivery.", False, ""
rst.MoveNext
Loop
Else
MsgBox "No Query Results To Process!", vbInformation
End If
The problem is that it will only read the first record of
Ship_Confirmation_Email - it will send the total number of emails that there
are records, but every one that comes is in is of the first record. Should I
not be using the DLookUp or should it be moved? I was hoping by moving the
variables into the loop statement it would then change for each record.
Please let me know where I messed up, thanks!
-gary
thanks to help from Daniel P, I got the ground work for creating a loop
statement to be used to go through a select query and send an email to each
record. I have added code to set up the variables (and also believe this is
where the problem is) and here is the following code:
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("Ship_Confirmation_Email")
If rst.RecordCount > 0 Then 'ensure there is data
rst.MoveFirst 'goto the 1st recordset
Do Until rst.EOF 'End of file
Dim sAddress As String
Dim STD As String
Dim TID As String
Dim ST As String
sAddress = DLookup("ShipTo_Email", "Ship_Confirmation_Email")
STD = DLookup("Ship_Type_Description", "Ship_Confirmation_Email")
TID = DLookup("Tracking_ID", "Ship_Confirmation_Email")
ST = DLookup("Ship_Times", "Ship_Confirmation_Email")
DoCmd.SendObject acSendNoObject, , , sAddress, , , "Order Shipment
Notification - Creations by You", "This email is to serve notice that your
Creations by You order has shipped!" _
& vbNewLine _
& vbNewLine _
& "It was sent via " + STD + " " + TID + " and will take
approximately " + ST + " for delivery.", False, ""
rst.MoveNext
Loop
Else
MsgBox "No Query Results To Process!", vbInformation
End If
The problem is that it will only read the first record of
Ship_Confirmation_Email - it will send the total number of emails that there
are records, but every one that comes is in is of the first record. Should I
not be using the DLookUp or should it be moved? I was hoping by moving the
variables into the loop statement it would then change for each record.
Please let me know where I messed up, thanks!
-gary