HELP!!! ME IN OPENING ACCESS REPORT through vb6.0
Dear friends
I am using following code to open an access report through vb6.0.
This code is working fine when i am using office xp or office 2000 and vb6.0 but when i use office 97 and vb6.0,
This code open only main window of the acces but not the data base.
The code is.
VB Code:
Public Function PrintAccessReport(ByVal sReportName As String) As Boolean
PrintAccessReport = False
On Error GoTo ErrorHandler
'Dim acc As Access.Application
'Set acc = New Access.Application
Dim acc As Object
Set acc = CreateObject("Access.Application")
Dim db As DAO.Database
Dim strDbName As String
'Command2.Enabled = False
'strDbName = gsDataLocation & "\" & gsDBName
strDbName = App.Path & "\grp.mdb"
acc.Visible = True
Set db = acc.DBEngine.OpenDatabase(strDbName)
acc.OpenCurrentDatabase strDbName
acc.DoCmd.OpenReport sReportName, acViewPreview
'MsgBox "hello"
'acc.Application.DoCmd.PrintOut acPrintAll
'DoEvents
'acc.CloseCurrentDatabase
'db.Close
'Set db = Nothing
'Set acc = Nothing
'Success
PrintAccessReport = True
'MsgBox "Report has been Printed"
'Command2.Enabled = True
Exit Function
ErrorHandler:
MsgBox "An error occurred during the print of " & sReportName & " report." & vbCrLf & vbCrLf & "Notify MIS. Error " & Err.Number & " : " & Err.Description, vbCritical, "Unknown Error"
On Error Resume Next
acc.CloseCurrentDatabase
db.Close
Set db = Nothing
Set acc = Nothing
Exit Function
End Function
'End of the code.
Plz let me know what is lacking in the code so that i
could open report of acess through vb in almost every version of msoffice.
Plz!!! help me its urgent
Thanks in advance
Shivpreet2k1
Edit: Added [vbcode][/vbcode] tags for more clarity. - Hack
Re: HELP!!! ME IN OPENING ACCESS REPORT through vb6.0
Moved to reporting section.