Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 36
  • Last Modified:

Is it possible to use a variable in a set report statement?

I have the following code:

   Dim rpt As Report
   prpReportName = Application.CurrentObjectName
   Set rpt = Reports!prpReportName.Report

Open in new window


I get the error: 'The report name prpRepaortName is misspelled or doesn't exist... etc'

Thanks in advance,

CRB
0
Clive Beaton
Asked:
Clive Beaton
  • 2
1 Solution
 
als315Commented:
You should change syntax:
   prpReportName = Application.CurrentObjectName
   Set rpt = Reports(prpReportName)
   Debug.Print rpt.Name
1
 
PatHartmanCommented:
Without context it's hard to answer the question.  For example, when I write code that will be used with multiple forms (same for reports), I define the code in a standard code module so it will be available from any form that needs it.  When I call the code I pass in the current form.

Call SomeProcedure(Me)

Using the "Me" object passes the current object which is either a form or report to the called procedure.  Then at the receiving end, here's an example of a common procedure.
Public Sub LockControls(frm As Form, bLock As Boolean)
    Dim ctl As Control
    For Each ctl In frm.Controls
    Select Case ctl.ControlType
        Case acTextBox, acComboBox, acListBox, acCheckBox
            Select Case ctl.Tag
                Case "NoLock"
                    ctl.Locked = False
                Case "Lock"
                    ctl.Locked = True
                Case Else
                    ctl.Locked = bLock         'toggle locks
            End Select
        Case acOptionGroup, acOptionButton, acCheckBox      ''not working
             Select Case ctl.Tag
                Case "NoLock"
                    ctl.Locked = False
                Case "Lock"
                    ctl.Locked = True
                Case Else
                    ctl.Locked = bLock         'toggle locks
            End Select
        Case acCommandButton
            Select Case ctl.Tag
                Case "NoLock"
                    ctl.Enabled = True
                Case "Lock"
                    ctl.Enabled = False
                Case Else
                    ctl.Enabled = Not bLock         'toggle locks
            End Select
    End Select
Next ctl
Set ctl = Nothing
End Sub

Open in new window

0
 
Clive BeatonAccess DeveloperAuthor Commented:
ALS, thanks very much.  Worked perfectly.

Thanks Pat.  Useful Routine.

CRB
0
 
PatHartmanCommented:
You're welcome.  It's one of the true universal routines I use.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now