How to set criteria for SendObject acReport? (1 Viewer)

Keith Nichols

Registered User.
Local time
Today, 10:03
Joined
Jan 27, 2006
Messages
431
Hi,

The code shown below generates the reprot with no filtering. I want to have the report for the current record only based on the ProjectID.

StrCriterion = "[ProjectID]=" & Me![ProjectId]

DoCmd.SendObject acReport, stDocName, , , , , Subjecttxt, Messagetxt, , StrCriterion 'Mail report


What am I doing wrong?
 

Keith Nichols

Registered User.
Local time
Today, 10:03
Joined
Jan 27, 2006
Messages
431
Hi again,

I managed to get this working based on the question and answer from your link. Thanks.

Thanks Folks,

I've had a good search and got a bit further, but still not quite there.

I have a preview button on my form that uses this:

Private Sub Command18_Click()
On Error GoTo Err_Command18_Click

Dim stDocName As String

stDocName = "rptReq"


Dim strWhere As String
strWhere = "[TransactionID] = " & Me.TransactionID
DoCmd.OpenReport "rptReq", acPreview, , strWhere


Exit_Command18_Click:
Exit Sub

Err_Command18_Click:
MsgBox Err.Description
Resume Exit_Command18_Click

End Sub

That works nicely.

I have a MailReport Button that doesn't work so well!

I can't seem to get it to only mail a report of the current record, as the preview button nicely does.

It uses this code:

Private Sub MailReport_Click()


Dim stDocName As String

stDocName = "rptReq"

Dim strWhere As String
strWhere = "[TransactionID] = " & Me.TransactionID

DoCmd.SendObject acSendReport, stDocName, acFormatRTF, "graham@tspace.co.uk", , , "E-Req" & Format(Now(), " ddd m-d-yy"), _
pFriendlyName & " is attached --- " _
& "Regards, " & "Graham"


End Sub

Any Ideas?

Graham
Hi,
you can't use the where clause in the sendobject method. So either change your code to be used in the on open event of the report itself, or just base your report on a query...in the query criteria area of the 'TransactionID' field reference your form control e.g.:

[Forms]![YourForm]![TransactionID]

Now you can just open your report with:

DoCmd.OpenReport "rptReq", acViewPreview

And therefor you can also just use:

DoCmd.SendObject acSendReport, "rptReq", acFormatRTF, "graham@tspace.co.uk", , , "E-Req" & Format(Date, " ddd m-d-yy"), pFriendlyName & " is attached --- " & "Regards, " & "Graham"

HTH
Good luck
 
Last edited:

Users who are viewing this thread

Top Bottom