JeffBarker
Registered User.
- Local time
- Today, 03:56
- Joined
- Dec 7, 2010
- Messages
- 130
Hi all - apologies if any of the following is unclear, I'm just starting out on my VBA career and my boss/tutor is away from the office today!!
I have created a form which is used to check transfer orders placed on another form elsewhere in the database - once the user has checked the order details they tick a yes/no box, and then depending on where the order is going a fax or email will be generated, selected from two seperate buttons on the form.
The email button has the following code behind it:
Private Sub cmdEmail_Order_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim rsdate As DAO.Recordset
Dim SQL As String
SQL = "SELECT TF.ID, Whole.[Transfer Order Information], Whole.[TFO Contact], TF.DateSent, TF.Company, TF.Ad1, TF.Ad2, TF.Ad3, TF.Town, TF.Pcode, TF.Telephone, TF.Contact, TF.Notes, TF.[4_Qty], Whole.[Wholesaler Promotion] " & _
"FROM tblWholesalers as Whole INNER JOIN tblTFOrders as TF ON Whole.ID = TF.WholesalerID " & _
"WHERE TF.LTChecked=-1 AND Whole.[TFO Method]='EMAIL' AND TF.DateSent is null"
Set db = CurrentDb
Set rs = db.OpenRecordset(SQL, dbOpenDynaset)
Set rsdate = db.OpenRecordset("tblTFOrders", dbOpenDynaset)
If Not rs.EOF And Not rs.BOF Then
rs.MoveFirst
Do Until rs.EOF
SendEmail [Transfer Order Information], -True, "Customer Transfer Order", "To: " & rs![TFO Contact] & vbCrLf & _
"Email: " & rs![Transfer Order Information] & vbCrLf & _
"Date: " & rs!DateSent & vbCrLf & vbCrLf & _
"Site Details:" & vbCrLf & vbCrLf & _
rs!Company & vbCrLf & _
rs!Ad1 & vbCrLf & _
rs!Ad2 & vbCrLf & _
rs!Ad3 & vbCrLf & _
rs!Town & vbCrLf & _
rs!Pcode & vbCrLf & vbCrLf & _
"Telephone: " & rs!Telephone & vbCrLf & _
"Contact: " & rs!Contact & vbCrLf & vbCrLf & _
"Notes: " & rs!Notes & vbCrLf & vbCrLf & _
"Order Details:" & vbCrLf & vbCrLf & _
"Product: Maggi Instant Gravy" & vbCrLf & _
"Pack Size: 1.74kg Tub" & vbCrLf & _
"Quantity: " & rs![4_Qty] & vbCrLf & _
"Promotion: " & rs![Wholesaler Promotion] & vbCrLf & vbCrLf & _
"If for any reason this order cannot be placed on the system within 1 working day of " & rs!DateSent & " please call **** and ask for Mr Smith"
rsdate.FindFirst "ID =" & rs!ID
rsdate.Edit
rsdate!DateSent = Date
rsdate.Update
rs.MoveNext
Loop
Else
MsgBox "No emails to export"
End If
End Sub
Currently, once the check box has been ticked I have to browse to the next record and back again before the code recognizes that the order is there, and sometimes I even have to close the form completely and go back in in order for the code to work.
Would anyone be able to help or have any suggestions on how to get this working so that the order record is saved or gets updated before pressing the Email button, please?
Again, apologies if any of this is unclear...I'm still learning, and my trusty VBA for Dummies book isn't particularly helpful in this instance!
Many Thanks,
Jeff.

I have created a form which is used to check transfer orders placed on another form elsewhere in the database - once the user has checked the order details they tick a yes/no box, and then depending on where the order is going a fax or email will be generated, selected from two seperate buttons on the form.
The email button has the following code behind it:
Private Sub cmdEmail_Order_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim rsdate As DAO.Recordset
Dim SQL As String
SQL = "SELECT TF.ID, Whole.[Transfer Order Information], Whole.[TFO Contact], TF.DateSent, TF.Company, TF.Ad1, TF.Ad2, TF.Ad3, TF.Town, TF.Pcode, TF.Telephone, TF.Contact, TF.Notes, TF.[4_Qty], Whole.[Wholesaler Promotion] " & _
"FROM tblWholesalers as Whole INNER JOIN tblTFOrders as TF ON Whole.ID = TF.WholesalerID " & _
"WHERE TF.LTChecked=-1 AND Whole.[TFO Method]='EMAIL' AND TF.DateSent is null"
Set db = CurrentDb
Set rs = db.OpenRecordset(SQL, dbOpenDynaset)
Set rsdate = db.OpenRecordset("tblTFOrders", dbOpenDynaset)
If Not rs.EOF And Not rs.BOF Then
rs.MoveFirst
Do Until rs.EOF
SendEmail [Transfer Order Information], -True, "Customer Transfer Order", "To: " & rs![TFO Contact] & vbCrLf & _
"Email: " & rs![Transfer Order Information] & vbCrLf & _
"Date: " & rs!DateSent & vbCrLf & vbCrLf & _
"Site Details:" & vbCrLf & vbCrLf & _
rs!Company & vbCrLf & _
rs!Ad1 & vbCrLf & _
rs!Ad2 & vbCrLf & _
rs!Ad3 & vbCrLf & _
rs!Town & vbCrLf & _
rs!Pcode & vbCrLf & vbCrLf & _
"Telephone: " & rs!Telephone & vbCrLf & _
"Contact: " & rs!Contact & vbCrLf & vbCrLf & _
"Notes: " & rs!Notes & vbCrLf & vbCrLf & _
"Order Details:" & vbCrLf & vbCrLf & _
"Product: Maggi Instant Gravy" & vbCrLf & _
"Pack Size: 1.74kg Tub" & vbCrLf & _
"Quantity: " & rs![4_Qty] & vbCrLf & _
"Promotion: " & rs![Wholesaler Promotion] & vbCrLf & vbCrLf & _
"If for any reason this order cannot be placed on the system within 1 working day of " & rs!DateSent & " please call **** and ask for Mr Smith"
rsdate.FindFirst "ID =" & rs!ID
rsdate.Edit
rsdate!DateSent = Date
rsdate.Update
rs.MoveNext
Loop
Else
MsgBox "No emails to export"
End If
End Sub
Currently, once the check box has been ticked I have to browse to the next record and back again before the code recognizes that the order is there, and sometimes I even have to close the form completely and go back in in order for the code to work.
Would anyone be able to help or have any suggestions on how to get this working so that the order record is saved or gets updated before pressing the Email button, please?
Again, apologies if any of this is unclear...I'm still learning, and my trusty VBA for Dummies book isn't particularly helpful in this instance!
Many Thanks,
Jeff.
