The following code will convert the report to PDF and attach it to an new email using your default email client:
gTroop = Me.Troop 'global variable to be defined in global module and accessed from the query using a function
DoCmd.OpenReport "GirlScoutandTroopMatchNoParams", acViewPreview, , "TroopLeaders.Troop=" & Me.Troop
DoCmd.SendObject acSendReport, "<NameOfReport>", "PDF", "johnbloggs@gmail.com"
You can use some more parameters to include subject and/or body text and/or to denote whether or not the email gets sent without showing in the email client.
The problem is that SendObject
does not provide an option for specifying criteria!
Therefore you have to write the report's underlying query, in such a way that it can get the criteria from the global variable.
Public Function GetTroopValue() as long
GetTroopValue = gTroop
End Function
Then in the underlying query you will use:
SELECT ... WHERE Troop = GetTroopValue()