Hi, was wondering if someone can please take a look at my code because it is not giving me the output on the email body.
Basically i have a button on my form that on the event it is clicked it should export all the records on the current form to the body of my email. The problem with my current code is it exports all the records on the query and not the form. When i change db.OpenRecordset ("qry_IRS Query",dbOpenDynaset) to ("frm_IRS Query",dbOpenDynaset) nothing appears on the email body and i get a run time error 3078 - cannot find input table or query frm_IRS Query. Can someone kindly help please. Thanking whoever in advance for your assistance. My current code as below:
Dim db As DAO.Database
Dim rec As DAO.Recordset
Dim olItem As Variant
Dim olMailItem As Variant
Dim olApp As Object
Dim strTo As String
Dim strcc As String
Dim strBody As String
Set olApp = CreateObject("outlook.application")
Set olItem = olApp.CreateItem(olMailItem)
olItem.Display
olItem.To = "email address"
olItem.cc = "email address"
olItem.Subject = "Derivatives Confirmation"
olItem.Body = "Please confirm" & vbCrLf & "or i will kick you" & vbCrLf & vbCrLf
Set db = CurrentDb
Set rec = db.OpenRecordset("qry_IRS Query", dbOpenDynaset)
With rec
If Not (rec.BOF And rec.EOF) Then
rec.MoveLast
rec.MoveFirst
intCount = rec.RecordCount
For intLoop = 1 To intCount
olItem.Body = olItem.Body & rec("ContractNo") & rec("ClientName") & rec("RateSet Date") & rec("Pay/Rec") & rec("Currency") & rec("Amount")
rec.MoveNext
Next intLoop
End If
End With
Set olApp = Nothing
Set olItem = Nothing
Basically i have a button on my form that on the event it is clicked it should export all the records on the current form to the body of my email. The problem with my current code is it exports all the records on the query and not the form. When i change db.OpenRecordset ("qry_IRS Query",dbOpenDynaset) to ("frm_IRS Query",dbOpenDynaset) nothing appears on the email body and i get a run time error 3078 - cannot find input table or query frm_IRS Query. Can someone kindly help please. Thanking whoever in advance for your assistance. My current code as below:
Dim db As DAO.Database
Dim rec As DAO.Recordset
Dim olItem As Variant
Dim olMailItem As Variant
Dim olApp As Object
Dim strTo As String
Dim strcc As String
Dim strBody As String
Set olApp = CreateObject("outlook.application")
Set olItem = olApp.CreateItem(olMailItem)
olItem.Display
olItem.To = "email address"
olItem.cc = "email address"
olItem.Subject = "Derivatives Confirmation"
olItem.Body = "Please confirm" & vbCrLf & "or i will kick you" & vbCrLf & vbCrLf
Set db = CurrentDb
Set rec = db.OpenRecordset("qry_IRS Query", dbOpenDynaset)
With rec
If Not (rec.BOF And rec.EOF) Then
rec.MoveLast
rec.MoveFirst
intCount = rec.RecordCount
For intLoop = 1 To intCount
olItem.Body = olItem.Body & rec("ContractNo") & rec("ClientName") & rec("RateSet Date") & rec("Pay/Rec") & rec("Currency") & rec("Amount")
rec.MoveNext
Next intLoop
End If
End With
Set olApp = Nothing
Set olItem = Nothing