Filter a Report before DoCmd.SendObject (1 Viewer)

diode666

New member
Local time
Today, 06:41
Joined
Jan 19, 2018
Messages
3
Hi
I want to click button in a form and generate a pdf based on the current record in the form.

I have 2 modules that are not perfect
Code:
Function EmalReport_VBA()
On Error GoTo EmalReport_VBA_Err
    Option Compare Database
    DoCmd.SendObject acReport, "PDFFormat(*.pdf)", "e", "", "ailbcc", "Subject", "Message Text", True, ""

EmalReport_VBA_Exit:
    Exit Sub
EmalReport_VBA_Err:
    MsgBox Error$
    Resume EmalReport_VBA_Exit
End Sub
This is perfect but the form/pdf is not filtered and sends all records.

This filters the form to the current record but leaves me in the preview window where I cant populate the email body and fields programmatically.

Code:
Private Sub Preview_Button_Click()
DoCmd.OpenReport "Item", acViewPreview, , "[ID]=" & Me.ID
End Sub
Can anyone help me filter the first option. I notice that even is the form has a filter applied, DoCmd.SendObject seems to ignore the filtering.

I have really spent some hours on this, any help appreciated
 

diode666

New member
Local time
Today, 06:41
Joined
Jan 19, 2018
Messages
3
After I posted I found the answer in another thread.

I set the ID in the query to the form control of the same and it works super smooth... the absolute joy :).


John big Booty
AWF VIP



Join Date: Aug 2005
Location: Planet 10, by way of the Eighth Dimension
Posts: 8,263
Thanks: 113
Thanked 1,003 Times in 864 Posts



Re: Filter for DoCmd.SendObject acSendReport
There is no Where condition in the Send object method. What you need to do, is put the use the criteria Forms!YourFormName!YourControlName in the query that you are using to populate your Report.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:41
Joined
May 7, 2009
Messages
19,231
You can open the report in
PrintPreview but you can also
hide it:


docmd.OpenReport ReportName:="Item",View:=acViewPreview,WindowMode:=acHidden,WhereCondition:="[ID]=" & ME.ID
 

Users who are viewing this thread

Top Bottom