Dynamically Change Recordsource of a Subreport (3 Viewers)

TheSearcher

Registered User.
Local time
Today, 16:17
Joined
Jul 21, 2011
Messages
406
If txt_Sex on Main Report = "M" then I want the recordsource of Subreport1 to be q_Male else q_Female.

Code:
If Parent!txt_Sex = "M" Then
    Me.RecordSource = q_Male
Else
    Me.RecordSource = q_Female
End If

Is this the correct code?
Do I place it in the subreport? If so, on which event?
Any help would be appreciated.
 
No guarantees but the using the Detail Format event to manipulate the subreport.
 
I succeeded by placing the code in the "On Activate" event of the parent report.
 
This question raises a red flag to me. If the two queries, q_Male and q_Female, have the same fields and source data (other than the gender), I would consider adding a gender column to one query with either an M or F value. Then use the Link Master/Child properties of the report and subreport to filter the subreport data by gender. This would require no code and only a single record source query.
 

Users who are viewing this thread

Back
Top Bottom