?
Solved

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

Posted on 2013-01-03
4
Medium Priority
?
571 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 2000 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
There are many software programs on offer that will claim to magically speed up your computer. The best advice I can give you is to avoid them like the plague, because they will often cause far more problems than they solve. Try some of these "do it…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

764 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