create reports from VBA

Discussion in 'AutoCAD' started by Kumar, Feb 10, 2004.

  1. Kumar

    Kumar Guest

    Hello everyone,
    i am working for customization of AutoCad using VBA and i have linked Access database to AutoCad using DAO objects. I have created reports in microsoft acces and i want to run/preview reports using command button from CAD interface(Created using VBA).
    Do have any idea how can i operate Microsoft Access reports from interface.???
    OR
    any other method to generate reports from AutoCAD VBA???
     
    Kumar, Feb 10, 2004
    #1
  2. Kumar

    Hatch Guest

    Here is how I do it:
    I have a table of report names in the database.
    A list box in my program displays the reports table.
    This code runs whichever report the user selects.
    This way any report added can be automatically included in the program
    without any additional programming required:
    [vbcode]
    Private Sub lstReports_DblClick()
    Dim hAccess As Long
    ' get the macro name from the list box
    Dim sMacro As String
    rsReports.Filter = "ReportName = '" &
    lstReports.List(lstReports.ListIndex) & "'"
    sMacro = rsReports.Fields("Macro").Value
    rsReports.Filter = ""
    ' show the access report
    Dim appAccess As New Access.application
    Me.Hide
    appAccess.OpenCurrentDatabase strDatabaseName, False
    appAccess.Visible = True ' VERY IMPORTANT
    hAccess = appAccess.hWndAccessApp
    appAccess.DoCmd.RunCommand acCmdAppMaximize
    appAccess.DoCmd.RunMacro sMacro
    Do While hAccess = GetForegroundWindow
    Call Sleep(100)
    Loop
    Set appAccess = Nothing
    Me.Show
    Me.WindowState = vbNormal
    End Sub
    [/vbcode]
     
    Hatch, Feb 10, 2004
    #2
  3. Kumar

    Hatch Guest

    oops:
    You need this too, the reports recordset.
    [vbcode]
    public rsReports as ADODB.Recordset

    Public Sub Open_Reports()
    On Error Resume Next
    rsReports.Close
    ' open the purchase orders recordset order by order number
    rsReports.Open "SELECT * From Reports " & _
    "ORDER BY ReportName;", db, adOpenStatic,
    adLockOptimistic
    End Sub
    [/vbcode]
     
    Hatch, Feb 10, 2004
    #3
  4. Kumar

    Hatch Guest

    oops, oops
    Need this in a module too:
    [vbcode]
    Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Declare Function SleepEx& Lib "kernel32" (ByVal dwMilliseconds As Long,
    ByVal _
    bAlertable As Long)

    Public Declare Function GetForegroundWindow& Lib "user32" ()
    [/vbcode]

    Going back to sleep now...
     
    Hatch, Feb 10, 2004
    #4
  5. Kumar

    Norman Yuan Guest

    Reports in MS Access can only be opend inside Access application. So, you
    need to automate Access application (Access must be installed).

    Following code gives you some idea:

    Public Sub OpenReport()

    Dim acApp As Access.Application
    Set acApp=New Access.Application 'Launch Access
    acApp.Visible=True
    acApp.OpenCurrentDatabase("C:\myfolder\mymdb.mdb")

    acApp.DoCmd.OpenReport "Myreport", acViewPreview

    End Sub

    You need to set reference to Access Object Library (not needed if you use
    late binding, though).
    Once you learn more about Access's object model, you can have more control
    on hoew the report is generated/displayed


    Access database to AutoCad using DAO objects. I have created reports in
    microsoft acces and i want to run/preview reports using command button from
    CAD interface(Created using VBA).
     
    Norman Yuan, Feb 10, 2004
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.