Access VBA syntax for printing report

Posted on 2011-10-28
Last Modified: 2012-05-12
Thank you in advance for your help.

I am trying to print a report with VBA that restricts the output to one specific test. I am getting a type mismatch error. I think I am using the syntax for a string. The data is an integer. Below is the code that gives a type mismatch error.

Dim stDocName As String
    Dim intLinkCriteria As Integer

    stDocName = "Result Letter"
    intLinkCriteria = "[Test Number]=" & "'" & Me![Test Number] & "'"
    DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria

What would be the correct syntax?

Question by:Rwardlow
    LVL 61

    Expert Comment

       intLinkCriteria = "[Test Number]="  & Me![Test Number]
    LVL 61

    Accepted Solution

       Dim strLinkCriteria As String

        stDocName = "Result Letter"
        strLinkCriteria = "[Test Number]=" &  Me![Test Number]
        DoCmd.OpenReport stDocName, acViewPreview, , strLinkCriteria

    LVL 1

    Author Closing Comment


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    The first two articles in this short series — Using a Criteria Form to Filter Records ( and Building a Custom Filter ( — discuss in some detail how a form can be…
    In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now