How to use Openreport from vb6, with parameters ?

Posted on 2005-04-10
Last Modified: 2012-06-27

Have a vb6.0 project that calls different reports that are stored in a access db.

What i need is a way to call a report with one or more parameters.
How can i do this, please give me the source-code for calling reports with parameters.

Her are the code i use today (without parameters)
   oAcc.DoCmd.OpenReport ReportName:=strReportName, & _

Need this code today.


Question by:team2005
    LVL 21

    Expert Comment

    Hi team2005,
    There's a great tip on it:
    Quote for You the essense:
    You'll need the API and Access bind as You probably allready know:
    'API Declarations
    Private Declare Function ShowWindow Lib "user32.dll" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
    Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

    'API Message Constants
    Private Const SW_MAXIMIZE = 3
    Private Const SW_NORMAL = 1
    'add the Microsoft Access 8.0 Object Library to the project references...Create a Form with three Command Buttons and enjoy with this code
    'Create a new Access Instance
    Dim appAccess As New Access.Application

    Public Sub MaximizeAccess()
        'Maximize Access Application
        Dim hWnd As Long

        hWnd = FindWindow("OMain", "Microsoft Access")
        If hWnd <> 0 Then
            ShowWindow hWnd, SW_NORMAL
            ShowWindow hWnd, SW_MAXIMIZE
        End If
    End Sub
    'Print an Access Report
    Private Sub Command2_Click()
        appAccess.DoCmd.OpenReport "Catalog", acViewNormal
    End Sub

    'Open an Access Form
    Private Sub Command1_Click()
        appAccess.DoCmd.OpenForm "Categories", acNormal, , , , acDialog
    End Sub

    Hope It helps
    LVL 2

    Author Comment


    Need code to start a report with parameters, not to start a report ?

    Her are the code i use today (without parameters)
       oAcc.DoCmd.OpenReport ReportName:=strReportName, & _

    Need to call report with parameters min. 2 parameters. Found out that i can
    use this code:

    strWhere = "SORTSEQ >=" & "100"
    With oAcc
      .Visible = False
      .DoCmd.OpenReport strReportName, acViewPreview, , strWhere
    End With

    Working just fine with 1 parameter, but how do i use it with more then one parameter.
    If you can give me the code to do that, i give you the 500 points.


    LVL 69

    Accepted Solution

    strWhere = "SORTSEQ >= 100 AND FieldName2 = ThisValue"
    LVL 2

    Author Comment


    Thats working 100%, thanks.



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    779 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

    14 Experts available now in Live!

    Get 1:1 Help Now