Solved

String variable used as report name

Posted on 2013-02-07
3
337 Views
Last Modified: 2013-02-07
I have a list of subreport names in a table. The user wants to be able to see many reports on one. I created a form with the report names and created one report that contains many subreports. The reports the user wants to see are made visible. I need to make the subreports visible using the variable. I am trying to move the report name to a string variable and call it this way:

dim rptName as string
dim rs as dao.recordset
dim cd as dao.database
dim strSQL as string
set cd = currentDB
strSQL = "Select ReportName from ReportList"
set rs = cd.openrecordset(strSQL)

For i = 1 To rs.RecordCount
  rptName = rs!ReportName
  Reports(rptName).Visible = False
rs.MoveNext
Next

I get an error saying that the report is misspelled or refers to a report that doesn't exist. The name of the report is correct but it has single quotes around it which may be the problem.
0
Comment
Question by:LeLeBrown
  • 2
3 Comments
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 38865648
That is because they are no longer "reports" if they are embedded in another report, they are subreport controls.  Try:

For i = 1 To rs.RecordCount
   rptName = rs!ReportName
   Reports(MainReportName).Controls(rptName).Visible = False
   rs.MoveNext
Next

This of course assumes that the subreport controls in you main report all have their Name property set to the name of the form that is the sourceObject for that control.
0
 

Author Closing Comment

by:LeLeBrown
ID: 38865683
That worked. Thanks!!
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 38865732
You are welcome, glad I could help.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question