command button in subform continuous form not working

hockey8837

Registered User.
Local time
Today, 18:50
Joined
Sep 16, 2009
Messages
106
Hi,
I have two command buttons in a subform "sbfScoutRegDetails", one that launches a report and the other attaches the report pdf to an email, associated with the record ID when clicked.

Both of these buttons work fine when just the subform itself is open, but when viewing it in its main form, I get a window saying 'enter parameter value' for "Forms!sbfScoutRegDetails!ID" (this is the WHERE condition in the macro).The report then opens with all the record information blank.

The full WHERE condition
Code:
[ID]=[Forms]![sbfScoutRegDetails]![ID]

I've attached a screen shot of my form.

Not sure if it's because of using a continuous form as a subform? I need the user to be able to view/print or email a contract to each group/contact that signs up.

Thanks!
 

Attachments

  • scout form.PNG
    scout form.PNG
    62.4 KB · Views: 739
So, if the continuous form with my control button "cmdScoutContract" is on a subform ("sbfScoutRegDetail") within the subform "sbfScoutProgDetails", the code in VBA should be something like this..but probably not quite this because it's not working...? :/

Code:
Private Sub cmdScoutContract_Click()
   'Display record in rptScoutReciept report
    DoCmd.OpenReport "rptScoutReciept", acViewPreview, , "ID = " & Me!sbfScoutRegDetails.sbfScoutProgDetails.ID
End Sub

FYI "sbfScoutProgDetails" is on the main form "frmScoutProgramDetails"

Thanks for your help!
 
If the code is on the subform try

DoCmd.OpenReport "rptScoutReciept", acViewPreview, , "ID = " & Me.ID

which would work whether it's a form or subform.
 
Excellent!
This worked great.

Got any suggestions for my command button 'click to email' for the same report from the same subform?

Here's my current Macro code:
Code:
Open Report
Report Name: rptScoutReciept
View: Report
Where: [ID]=[Forms]![sbfScoutRegDetails]![ID]
Window Mode: Normal

EmailDatabaseObject
ObjectType: Report
ObjectName: rptScoutReciept
OutputFormat: PDF Format
To: [ContactName] & [IIf(Nz([EmailAddress]) <> "," [EmailAddress] & "]")
CC:
Bcc:
Subject: Discovery Tour Contract
Message Text:
Edit Message: Yes
Template File:
 
If you mean the emailing part, the VBA equivalent is

DoCmd.SendObject

with the appropriate arguments.
 

Users who are viewing this thread

Back
Top Bottom