Link to home
Start Free TrialLog in
Avatar of team2005
team2005

asked on

How to use Openreport from vb6, with parameters ?

Hi!

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, & _
            View:=acNormal

Need this code today.

Thanks.

Tor
Avatar of oleggold
oleggold
Flag of United States of America image

Hi team2005,
There's a great tip on it:
http://www.andreavb.com/tip110002.html
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
 
Usage
'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
Cheers!
Avatar of team2005
team2005

ASKER

Hi!

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, & _
            View:=acNormal

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
  .DoCmd.PrintOut
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.

Thanks

Tor
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi!

Thats working 100%, thanks.

Cheers,
Tor