recordset in a DoCmdSendObject method

Leo_Polla_Psemata

Registered User.
Local time
Today, 07:40
Joined
Mar 24, 2014
Messages
364
Code:
Private Sub Report_Current()

Dim RsEmail as dao.recordset
set RsEmail = currentdb.openrecordset ("your table name")
With rsEmail
sMessageBody = "Email body Text"
Do Until .EOF
sMessageBody = sMessageBody & vbCrLf & .Fields(POL) & " " & .Fields(POD) & "" & .Fields(RATE20) & "" & .Fields(RATE40)
.MoveNext
Loop

DoCmd.SendObject , , , , , , "test test", sMessageBody, True, ""

End With
End Sub

Hi, I need your help, I am not programmer, nor IT , just one clerk who enjoy access and I have solved too many problems in my daily job.

I have used the above code successfully and I compose outlook emails,
on the email body I display many rows as per table or query ("your table name").

Now, i want to do the same but , the query ("your query name") is a =Forms!FormName.Text1 type
and the code asks for parameters. It doesn't work.

I try to copy my query as recordset as per below example.
I transfer the whole sql syntax correctly , the "Where" is also there.


strSQL = "SELECT FrRef.ID, FrRef.frref, FrRef.effective, FrRef.expire, Tbl_Oferta.ID, Tbl_Oferta.ClientCode, " _
& "sql copy paste, no need to display the entire query , " _
& "WHERE (((FrRef.frref)=[forms]![frm_frrefoferta]![frref]) AND ((Tbl_Oferta.ClientCode)=[Forms]![Frm_FrRefOferta]![Tbl_Oferta].[form]![ClientCode])); "


I don't know how to make the
set RsEmail = currentdb.openrecordset ("your table/query name")
work like this
set RsEmail = currentdb.openrecordset ("run this strsql")

The syntax of the whole code
 
Don't send a recordset, create a QUERY, and send the query.
Use the SQL and make a query from it.
 
It doesn't work because the query has a criteria
=Forms!FormName.Text1
and the code asks for parameters.

If I replace the =Forms!FormName.Text1 with the actual piece of data, say "ref5", tnen it works


In this site, i have found other older posts which the same problem exist.
 
Last edited:
When you have parameters in a query that you use in a recordset you need to declare the parameters in the code. This web page has a code example where this has been done. Note the different way the recordset will be opened when you do this. It will be

Code:
Set RsEmail = qdf.OpenRecordset()

Instead of

Code:
set RsEmail = currentdb.openrecordset ("your table name")

because the query will be opened like

Code:
Set qdf = db.QueryDefs("your table name")
 

Users who are viewing this thread

Back
Top Bottom