Results 1 to 2 of 2

Thread: HELP!!! ME IN OPENING ACCESS REPORT through vb6.0

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2004
    Posts
    260

    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:
    1. Public Function PrintAccessReport(ByVal sReportName As String) As Boolean
    2.  
    3. PrintAccessReport = False
    4. On Error GoTo ErrorHandler
    5.  
    6. 'Dim acc As Access.Application
    7. 'Set acc = New Access.Application
    8. Dim acc As Object
    9. Set acc = CreateObject("Access.Application")
    10. Dim db As DAO.Database
    11. Dim strDbName As String
    12. 'Command2.Enabled = False
    13. 'strDbName = gsDataLocation & "\" & gsDBName
    14. strDbName = App.Path & "\grp.mdb"
    15. acc.Visible = True
    16. Set db = acc.DBEngine.OpenDatabase(strDbName)
    17. acc.OpenCurrentDatabase strDbName
    18.  
    19. acc.DoCmd.OpenReport sReportName, acViewPreview
    20. 'MsgBox "hello"
    21. 'acc.Application.DoCmd.PrintOut acPrintAll
    22.  
    23. 'DoEvents
    24.  
    25. 'acc.CloseCurrentDatabase
    26. 'db.Close
    27. 'Set db = Nothing
    28. 'Set acc = Nothing
    29.  
    30. 'Success
    31. PrintAccessReport = True
    32. 'MsgBox "Report has been Printed"
    33. 'Command2.Enabled = True
    34. Exit Function
    35. ErrorHandler:
    36. MsgBox "An error occurred during the print of " & sReportName & " report." & vbCrLf & vbCrLf & "Notify MIS. Error " & Err.Number & " : " & Err.Description, vbCritical, "Unknown Error"
    37. On Error Resume Next
    38.  
    39. acc.CloseCurrentDatabase
    40. db.Close
    41. Set db = Nothing
    42. Set acc = Nothing
    43.  
    44. Exit Function
    45.  
    46. 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
    Last edited by Hack; Nov 15th, 2005 at 06:59 AM.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: HELP!!! ME IN OPENING ACCESS REPORT through vb6.0

    Moved to reporting section.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width