Solved: Emailing a report using VBA for Access

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Bradybunch

Thread Starter
Joined
Sep 10, 2009
Messages
211
I have a form open with all the details i need, and i can email a report, using the code below, i just cant get it to email the report that is open for an individual "DevelopmentID". I just dont know how to link the "DevelopmentID" :confused:

Private Sub CmdEmail4_Click()
On Error GoTo CmdEmail4_Click_Err
DoCmd.SendObject acReport, "RptClientAll", "PDFFormat(*.pdf)", "", "", "", "All Client Detail", "", True, ""

CmdEmail4_Click_Exit:
Exit Sub
CmdEmail4_Click_Err:
MsgBox Error$
Resume CmdEmail4_Click_Exit
End Sub

Any body got any sugestions please? The normal Macro does not link, so im resorting to VBA. ive converted the macro to show the VBA as above. Ive tried different ways like below, but it does not link it still:

Private Sub CmdEmail4_Click()
On Error GoTo CmdEmail4_Click_Err

DoCmd.SendObject acReport, "RptClientAll", "PDFFormat(*.pdf)", "", "", "", "All Client Detail", "", True, "", "[DevelopmentID]=" & Me![DevelopmentID]

CmdEmail4_Click_Exit:
Exit Sub
CmdEmail4_Click_Err:
MsgBox Error$
Resume CmdEmail4_Click_Exit
 

OBP

Joined
Mar 8, 2005
Messages
19,895
If you just want to output the current record then the easiest way is to use a "filtering" query for the report's record source.
 

Bradybunch

Thread Starter
Joined
Sep 10, 2009
Messages
211
How do you mean a filtering query? My report has two sub reports on it too, which is bringing together two lots of information. It works fine, i just cant seem to get it to filter on the DevelopmentID. It always goes to the first record in the list.
 

Bradybunch

Thread Starter
Joined
Sep 10, 2009
Messages
211
I have it working fine printing, it seems to filter perfectly with this code:

Private Sub CmdPrintAll4_Click()
If IsNull(Me!DevelopmentID) Then
MsgBox "Please select a valid record", _
vbOKOnly, "Error"
Exit Sub
End If
DoCmd.OpenReport "RptClientAll", acViewReport, , _
"DevelopmentID = " & Me!DevelopmentID
End Sub

However i have another button that i want to press to email the document instead of printing it.
 

OBP

Joined
Mar 8, 2005
Messages
19,895
In the Main Report's query I would use the Criteria in the DevelopmentID column
Forms![formname]![DevelopmentID]
where formname is the name of the form.
There should not be any other records in the query and report other than the one for the form's DevelopmentID.
 

Bradybunch

Thread Starter
Joined
Sep 10, 2009
Messages
211
That does not seem to work... i have attached the DB for you so you can see what it is im trying to do.

FrmOccupantsList is the main form, and then you can view each entry from with in there. On the form FrmOccupantView i have the button to email the data using the report RptClientAll. Both Form and report use the query QryOccupantsList. If you try the print all details button it works perfectly, which is what i want the email to do.
 

Attachments

OBP

Joined
Mar 8, 2005
Messages
19,895
This is how I meant, see the query "QryCurrentOccupants" and report "RptCurrentClient", they only return the Current record displayed in the "FrmOccupantView" form.
 

Attachments

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Top