Send an Query output with a Email using "sendObject" function

D

DontKnow

Hi Guys,

If I wanted to include the output from a query in an email using the
"sendobject" function I receive an error sqaying thast the query is empty.
(The actual error I receive is: "The Object Type argument for the action or
method is blank or invalid").

Yet when I open the query, it does in fact have records in it.

Here is my cod e for the send object:
Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Dim rst As DAO.Recordset
Dim strsql As String
Dim nextdate As String
Dim emailaddress As String

nextdate = DateAdd("m", 1, Date) ' one month ahead of current date for all
Rego Expiry dates
emailaddress = "(e-mail address removed)"

strsql = "SELECT Rego.RegoID, Rego.RegoNo, Rego.RegoExpiryDate,
Rego.VehicleMake, Rego.VehicleModel " & _
"FROM Rego " & _
"WHERE (((Rego.RegoExpiryDate) Between Date() And #" & nextdate & "#));"
Set dbs = DBEngine(0)(0)

If DCount("Name", "msysobjects", "[Name] = 'qrytemp'") = 0 Then

Set qdf = CurrentDb.CreateQueryDef("qrytemp", strsql)
'DoCmd.OpenQuery "qrytemp"

'Set rst = qdf.OpenRecordset
'rst.MoveFirst
'MsgBox rst.Fields("RegoNo")

DoCmd.SendObject acSendQuery, qrytemp, acSendTable, emailaddress, , , "Sue
You need to update the Rego Expiry dates for the following cars!!", , False

Else
Set qdf = CurrentDb.QueryDefs("qrytemp")
qdf.SQL = strsql
DoCmd.OpenQuery "qrytemp"
MsgBox qrytemp
DoCmd.SendObject acSendQuery, qrytemp, acSendTable, emailaddress, , , "Sue
You need to update the Rego Expiry dates for the following cars!!", , False
'MsgBox rst.Fields("RegoNo")
Set rst = qdf.OpenRecordset
rst.MoveFirst
MsgBox rst.Fields("RegoNo")
End If



Please help me, as I cannot fix the error,

many thanks,
 
P

Paolo

Hi DontKnow,
the third argument of your sendobject (ie acSendTable) is wrong. It must be
the output format.
The following lines are taken from the Microsoft Access help
outputformat one of the following intrinsic constants:
acFormatDAP
acFormatHTML
acFormatRTF
acFormatTXT
acFormatXLS
If you leave this argument blank, Microsoft Access prompts you for the
output format.

HTH Paolo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top