Solved

How to remove quotation marks from a report name within a variable

Posted on 2013-01-03
4
568 Views
Last Modified: 2013-01-03
I am using the string variable ReportName which contains the name of a report "Rpt_MonthlyReport121231".  (The reason for the variable is that the name of the report changes every month.)

It works great when used in the statement:  DoCmd.OpenReport ReportName, acViewPreview, , "HHID=" & ClientNowPrinting  

However it does not work in this statement:  Totalpages = Reports![ReportName].Pages

I discovered the reason is that the latter statement can't accept the QUOTATION MARKS around the name of the report.  (The statement works fine if I simply write Rpt_MonthlyReport in the brackets without quotes)

How can I use the variable and eliminate the quotes?
0
Comment
Question by:David_W_R
  • 2
  • 2
4 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 38740712
Try this:

Totalpages = Reports(ReportName).Pages
0
 

Author Closing Comment

by:David_W_R
ID: 38740750
Extend arm, clench fist and pull quickly toward shoulder.  Utter "YES!"
Thanks, mbizup.  Saved SO much time.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38740802
Glad to help out!

BTW, you can do the same with other collections such as forms, controls  etc...


msgbox Forms(strFormName).Controls(strControlName).Value

Or loop through collections getting all elements generically using 'Each':

dim ctl as Control
For Each ctl in Me.Controls
      If ctl.ControlType = actextbox then ctl.BackColor = vbBlue
Next

Open in new window

0
 

Author Comment

by:David_W_R
ID: 38741584
Much appreciated.  I'm making a paper note place next to my keyboard so I can review this format often until it becomes a permanent part of my repertoire.  Could have been very helpful in the past, and I'm sure it'll come in handy again soon.
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

680 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