This has been discussed many times in the VB 5&6 forum....
Is MS ACCESS on the machine?
If so, then you can use the "Microsoft Access Objects Library" dll. Then you only need to reference it and create an object variable and run the methods to open the database and DoCmd to print the report:
Public Sub OpenAccessReport(ByVal DbPathAndName As String, ByVal ReportName As String, Optional ByVal lAction As Long = cPreview)
'For the below MS ACCESS must be on the client machine, as you do not have rights to distribute the DLL
'Or you can use the SnapShotViewer.Exe (Free from the
'If you do it this way then you will need to add a reference the Dll under PROJECT|REFERENCES
'Dim oAccess As New Access.Application
'If you do it this way then it will be a little slower initally, but you do not have to set a reference to the DLL Dim oAccess As Object
Dim I As Integer
Const acCmdAppMaximize = 10 'Const acCmdPageSetup = 32
Set oAccess = CreateObject("Access.Application"
With oAccess
.OpenCurrentDatabase FilePath:=DbPathAndName
If lAction = cPreview Then .Visible = True
.DoCmd.OpenReport ReportName, lAction
On Error Resume Next
'.RunCommand acCmdPageSetup
End With
'On Error Resume Next
'oAccess.Quit
'Set oAccess = Nothing
End Sub
[/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
With objAccess
.OpenCurrentDatabase filepath:=dbName
If Preview = acPreview Then
.Visible = True
.DoCmd.OpenReport rptName, Preview
Else
.DoCmd.OpenReport rptName
End If
End With
End Sub
Private Sub Form_Load()
Set objAccess = CreateObject("Access.Application"
End Sub
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
objAccess.Quit
On Error GoTo 0
Set objAccess = Nothing
End Sub
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.