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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how 2 print ms access report using VB

Status
Not open for further replies.

athos07

Programmer
Aug 1, 2002
19
AU
how can i print ms access report (my back end database) using visual basic.??

thanks
 
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 site).

'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!
 
i have already done it but anyway, thank you to for your code at least i will have an alternative code for this. my code is this:

:) thank you very much

Dim objAccess As Object

Private Sub Command1_Click()
Dim dbName As String
Dim rptName As String
Dim Preview As Long
Const acNormal = 0
Const acPreview = 2

dbName = "c:\objaccess\gasi2.mdb"
rptName = "bidac"
Preview = acPreview 'acNormal

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top