2

I'm trying to open and filter a report based on the report that a user selects from a combobox in a form. To simplify the example, here's what I'm dealing with:

First I'm opening the report:

Dim strReportName As String
strReportName = "General Information"
DoCmd.OpenReport strReportName, acViewPreview

This works fine, the problem arrises when I'm trying to apply a filter.

With Reports!strReportName
    .Filter = strFilter
    .FilterOn = True
End With

The problem I can't find my way around, is that it seems impossible to use a variable reportname in this syntax. Needless to say, the error thrown by VBA is as follows:

Run-time error '2451':

The report name 'strReportName' you entered is misspelled or refers to a report that 
isn't open or doesn't exist.

My question is: Is there any way to alter this statement into letting me filter the report that's currently open without needing to hardcode the reportnames into VBA?

1
  • the only way I can think of its to insert a module programmatically and replace the strReportName with the actual name. I wouldn't really recommend doing it that way but it's the only solution I am aware of Commented Nov 20, 2013 at 13:52

1 Answer 1

0

When strReportName is a variable which contains the name of a report, you discovered this fails ..

With Reports!strReportName

Use this instead ...

With Reports(strReportName)
Sign up to request clarification or add additional context in comments.

1 Comment

Why are the biggest braincrackers always so straightforward in the end... Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.