• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 28
  • 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
CRB1609
Asked:
CRB1609
  • 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
 
CRB1609Author 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

Join & Write a Comment

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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