Solved

String variable used as report name

Posted on 2013-02-07
3
332 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now