print access report in visual basic

print access report in visual basic

Post by Pucc » Tue, 22 Apr 2003 19:01:14



Hi
I used this code to print the access report in VB
but it gave me the error '2486'
does anyone know where's the problem?
Thanks!

      Pucca

Dim appAccess As New Access.Application
Dim strReportName As String
Dim strformname As String
Dim strMacroName As String
Dim strDBpath As String
Const constrDBName As String = "app.path & \gestmail.mdb"

Private Sub Command2_Click()
On Error Resume Next
strReportName = "Relatorio_escolha" <-- this report name exist in
access report

'Assigns an object reference to a variable or property.
Set appAccess = New Access.Application

With appAccess
'open an existing database as the current database.
.OpenCurrentDatabase constrDBName

'specify whether a Microsoft Access application is minimized
.Visible = True

'open a report in Print Preview
.DoCmd.OpenReport strReportName, acViewPreview

'print the report immediately
.DoCmd.OpenReport strReportName, acViewNormal 'Print the report

End With

'disassociate an object variable from an actual object
'memory and system resources associated with the object to
'which the variables refer are released
Set appAccess = Nothing

' erros

If Err.Number = 3011 Then
MsgBox ("Form with 'Old' name cannot be found, maybe it has already
been renamed.")
    appAccess.Quit
    Set appAccess = Nothing
    Exit Sub
ElseIf Err.Number = 7866 Then
    MsgBox (strDBpath & " has been opened exclusively by another
user.")
    appAccess.Quit
    Set appAccess = Nothing
    Exit Sub
Else
MsgBox (Err.Number & "-" & Err.Description & " Please report this
error to your Administrator")
End If
End Sub