Acess Reports In VB6

R_L

Well-known member
  • Jan 21, 2007
    3,064
    46
    48
    Colombo
    try this man

    This code enables you to specify a Microsoft Access database open a report and print it out or open in preview form through Visual Basic.

    Create a module and place the following inside:

    Code:

    Option Explicit

    ' In other applications like Microsoft Visual Basic,

    ' you can include a reference to Microsoft Access to

    ' gain the use of Access constants. Or, use the following

    ' constant values...

    Global Const acNormal = 0

    Global Const acDesign = 1

    Global Const acPreview = 2

    ' -----------------------------------------------------

    ' Application Quit options...

    ' saves all objects without displaying a dialog box:

    Global Const acSaveYes = 0

    ' displays a dialog box that asks whether you want to save any

    ' database objects that have been changed but not saved:

    Global Const acPrompt = 1

    ' quits Microsoft Access without saving any objects:

    Global Const acExit = 2

    Sub PrintAccessReport(dbname As String, rptname As String, preview As Boolean)

    Dim objaccess As Object

    On Error GoTo PrintAccessReport_ErrHandler

    Set objaccess = CreateObject("Access.Application")

    With objaccess

    .OpenCurrentDatabase filepath:=dbname

    If preview = True Then 'Preview report on screen.

    .DoCmd.OpenReport reportname:=rptname, View:=acPreview

    .Visible = True

    .DoCmd.Maximize 'maximizes the Report window

    .DoCmd.Maximize 'maximizes Access window

    Else 'Print report to printer.

    .DoCmd.OpenReport reportname:=rptname, View:=acNormal

    DoEvents 'Allow report to be sent to printer.

    End If

    End With

    Set objaccess = Nothing

    Exit Sub

    PrintAccessReport_ErrHandler:

    MsgBox Error$(), , "Print Access Report"

    End Sub


    Now Call this procedure with a command button or whatever replacing the example below with the desired parameters. The first parameter requests the path to the database, the second requests the Report name, and the third requests the view state: True will open access and display the report, False will just print the report.

    Code:
    Call PrintAccessReport App.Path & "collectables.mdb", "Figures", True
     

    R_L

    Well-known member
  • Jan 21, 2007
    3,064
    46
    48
    Colombo
    ammatasiri den neh dekke.. oya illanne VB6 gena nehda.. appa.. wron wron.. meka hariyana ekak nehe.. meh VBA.. ahahah.. poddak inna.. try karala kiyannam...
     

    R_L

    Well-known member
  • Jan 21, 2007
    3,064
    46
    48
    Colombo
    try this bro.. .

    http://www.freevbcode.com/ShowCode.asp?ID=5254

    oke thiyenawa sample code an example.. download an follow like that...

    do u want to display ur report based on anything.. eh kiwuwe query ehekin ena result ehekatada neththam just displayin the report da... anyhow check dat ko...

    only difference is that u need to create a query and then include that query when calling for the report.. see if it helps.. sorry bout earlier.. i thought it was VBA. haha.. my bad..
     

    Sudantha_s

    Member
    Feb 2, 2007
    3,516
    7
    0
    Assassin Brotherhood
    R_L said:
    try this bro.. .

    http://www.freevbcode.com/ShowCode.asp?ID=5254

    oke thiyenawa sample code an example.. download an follow like that...

    do u want to display ur report based on anything.. eh kiwuwe query ehekin ena result ehekatada neththam just displayin the report da... anyhow check dat ko...

    only difference is that u need to create a query and then include that query when calling for the report.. see if it helps.. sorry bout earlier.. i thought it was VBA. haha.. my bad..


    mchan this is nt working :(... i was trying with Data Environments in VB but its not yet Successful ..Queries walin Report ekak ganna