Primary key as subject (1 Viewer)

Khushalay

Registered User.
Local time
Today, 08:53
Joined
Apr 16, 2016
Messages
180
I have a button that send a report in email. The code behind the button is

DoCmd.SendObject acSendReport, "", acFormatPDF, _
"email", "ccemail", , _
"Subject", , True

I want the subject to take the the primary key of the opened record. How to change the coding so that it takes it automatically every time.

Thanks
 

Minty

AWF VIP
Local time
Today, 16:53
Joined
Jul 26, 2013
Messages
10,387
Assuming your report is based on a query , and your button is on a form that has the current record primary key available simply put the forms field in the criteria of the report query.
Forms!YourFormName!ControlNameWithPrimaryKeyInIt
 

Khushalay

Registered User.
Local time
Today, 08:53
Joined
Apr 16, 2016
Messages
180
Yes, the button is on the report with the primary key on it and report is based on a query.

This code is working perfect except I want the primary key e.g 001 to be displayed as the subject of the email so that the recipient knows the record from the subject and can easily differentiate and search in their inbox.

The code where it says subject of the email, I need to insert the primary key of the record.
 

Minty

AWF VIP
Local time
Today, 16:53
Joined
Jul 26, 2013
Messages
10,387
Substitute the ID into the send command ;
Code:
Dim sSubject as string

[COLOR="Red"]sSubject [/COLOR]= Me.YourPrimaryKeyControl

DoCmd.SendObject acSendReport, "", acFormatPDF, "email", "ccemail", , [COLOR="red"]sSubject[/COLOR], , True
 

Users who are viewing this thread

Top Bottom