Variables in VBA and Report Controls

R

Rockn

I was wondering if there was a way to use a variable when referencing a control on a report? I would like to make a subReport visible when its default setting is invisible. I need to place the variable inside of the report collection reference something like this:

Criteria from Main form to create the variable:

If IsNull(Me.[Text147]) And IsNull(Me.Text133) Then
rptType = "rpt_CustomerCopy"
End If
If IsNull(Me.[Text147]) And Not (IsNull(Me.Text133)) Then
rptType = "rpt_CustomerCopyDisc"
End If

and this is what I want to use to hide the subReport on the footer of the report: The "here" is where I would like to use the variable if it is even possible.

Reports!HERE.Report!rpt_Change.Visible = True


Thanks!
 
J

John Spencer

Can't test right now, but you should be able to use

Reports.Controls(rptType).Report!rpt_Change.Visible = True

'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
 
R

Rockn

Nope, that didn't do it.

When you hover over the debug line it shows the rptType = "rptCustomerCopy"
which is the correct report.


John Spencer said:
Can't test right now, but you should be able to use

Reports.Controls(rptType).Report!rpt_Change.Visible = True

'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================

I was wondering if there was a way to use a variable when referencing a
control on a report? I would like to make a subReport visible when its
default setting is invisible. I need to place the variable inside of the
report collection reference something like this:

Criteria from Main form to create the variable:

If IsNull(Me.[Text147]) And IsNull(Me.Text133) Then
rptType = "rpt_CustomerCopy"
End If
If IsNull(Me.[Text147]) And Not (IsNull(Me.Text133)) Then
rptType = "rpt_CustomerCopyDisc"
End If and this is what I want to use to hide the subReport on the footer
of the report: The "here" is where I would like to use the variable if it
is even possible.

Reports!HERE.Report!rpt_Change.Visible = True


Thanks!
 
R

Rockn

Figured it out

Reports(rptType).Report!rpt_Change.Visible = True

Pretty close and thanks for the insight into this.

Rockn said:
Nope, that didn't do it.

When you hover over the debug line it shows the rptType =
"rptCustomerCopy" which is the correct report.


John Spencer said:
Can't test right now, but you should be able to use

Reports.Controls(rptType).Report!rpt_Change.Visible = True

'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================

I was wondering if there was a way to use a variable when referencing a
control on a report? I would like to make a subReport visible when its
default setting is invisible. I need to place the variable inside of the
report collection reference something like this:

Criteria from Main form to create the variable:

If IsNull(Me.[Text147]) And IsNull(Me.Text133) Then
rptType = "rpt_CustomerCopy"
End If
If IsNull(Me.[Text147]) And Not (IsNull(Me.Text133)) Then
rptType = "rpt_CustomerCopyDisc"
End If and this is what I want to use to hide the subReport on the
footer of the report: The "here" is where I would like to use the
variable if it is even possible.

Reports!HERE.Report!rpt_Change.Visible = True


Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top