Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening MS Access Reports with Visual Basic 6

Status
Not open for further replies.

rpk2006

Technical User
Apr 24, 2002
225
IN
I am using following code to view preview of a report built in MS Access.

Code:
Dim appAccess As Access.Application
        
        Set appAccess = New Access.Application
	appAccess.Visible = True	

        appAccess.OpenCurrentDatabase App.Path & "\data\eticketxp.mdb", True, "DevelopeR"

        appAccess.DoCmd.OpenReport "TestReport", acPreview, , "myOptionalCondition"
        
        appAccess.Quit

        Set appAccess = Nothing

But appAccess.Visible opens the main MS Access window along with my database. I just want to view preview.

Secondly, which one is easy for reporting, MS Access Reports or Crystal Reports.
 
Secondly: Access reports are more frendly and maybe, better then Crystal. For example, in Crystal is very annoing that you can not define the lenght of your fields (they depend on whatever your query returns at designtime).
But if you want to build an application with VB, you should not mixt it with Access (licence problems, etc.) Is more proffesional to do it with Crystal (or, if there are not very complex reports, they can be done with VB built in Report editor)

First: Access must start in order to display your report...

Hope I've been helpful,
Bogdan Muresan.
 
You can use some VBA code from withing the Microsoft Access application itself to "hide" the access window. e.g.

Code:
'hides the access window
Private Declare Function apiShowWindow _
Lib "user32" _
Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

Function fSetAccessWindow(nCmdShow As Long)
'hides the access window
    On Error GoTo errhandle

    Dim loX  As Long
    loX = apiShowWindow(hWndAccessApp, nCmdShow)
    fSetAccessWindow = (loX <> 0)
    
    Exit Function

errhandle:
Call ERROR_CONTROL
Exit Function
End Function

Private Sub Form_Open(Cancel As Integer)
'calls function to minimize the access window

fSetAccessWindow 2
 
End Sub

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
CreateObject("Access.Application") is only supported when the retail
version of Access is installed. When only the runtime Access is installed,
you cannot use CreateObject (or New Access.Application) or Getobject to
launch an instance of Access for automation.

This behavior is by design and has been this way since the release of
Access 95 (the first version of Access that you could automate). The
following article states this for Access 2002. Error 429 is the common
error but the article below states a different error that might occur:

Q295179 - ACC2002: Can't Use OLE Automation with Access Runtime

As a workaround, you must launch the msaccess.exe first, for example using
the Shell function. Once this is done, you can use GetObject to reference
the running instance of the Access runtime. Now you can automate it.
There is an example in the following KB where it mentions the Access
runtime:

Q296586 - ACC2002: How to Use Automation to Print Microsoft Access Reports
support.microsoft.com/support/kb/articles/q296/5/86.asp

On your development machine, you can switch to the Shell/Getobject approach
even for the retail version of Access so that you can still test on your
development machine. It works with either the retail or the runtime. One
drawback to having to launch the msaccess.exe is that you need to specify
the full path to it. Also, it is advised that you use the second argument
of the Shell function to give Access the focus, at least temporarily. Then
set focus back to your VB app or some other window. This ensures that
Access is registered in the ROT before you call Getobject. The following
articles explain this, and should be helpful if you decide to proceed with
automating the Runtime Access:

Q240794 - HOWTO: Determine the Path for an Office Application

Q238610 - PRB: GetObject or GetActiveObject Cannot Find Running Office App

For information and sample code for integrating Office with Visual Basic,
Visual C++, Internet Scripts, and other programming languages, please see
This site
contains the most up-to-date information for using developer tools for
Office integration and extensibility.

Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@earthlink.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top