Results 1 to 2 of 2

Thread: Help to use dsn in vb6.0 for report

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2004
    Posts
    260

    Help to use dsn in vb6.0 for report

    Dear Friends

    Below is the code call access report in vb 6.0 . This code has been got from the reply of ILJester. I want to use the code with data source name. that is i do not want to use

    strDbName = gsDataLocation & "\" & gsDBName
    and I want to use DSN Is there any way to do it.

    Plz!!! help Its urgent.
    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. Dim db As DAO.Database
    8. Dim strDbName As String
    9.  
    10. strDbName = gsDataLocation & "\" & gsDBName
    11. Set acc = New Access.Application
    12. 'acc.Visible = True
    13. Set db = acc.DBEngine.OpenDatabase(strDbName, False, False, ";PWD=yourpass")
    14. acc.OpenCurrentDatabase strDbName
    15.  
    16. acc.DoCmd.OpenReport sReportName, acViewPreview
    17. acc.Application.DoCmd.PrintOut acPrintAll
    18.  
    19. DoEvents
    20.  
    21. acc.CloseCurrentDatabase
    22. db.Close
    23. Set db = Nothing
    24. Set acc = Nothing
    25.  
    26. 'Success
    27. PrintAccessReport = True
    28. Exit Function
    29. ErrorHandler:
    30. MsgBox "An error occurred during the print of " & sReportName & " report." & vbCrLf & vbCrLf & "Notify MIS. Error " & Err.Number & " : " & Err.Description, vbCritical, "Unknown Error"
    31. On Error Resume Next
    32.  
    33. acc.CloseCurrentDatabase
    34. db.Close
    35. Set db = Nothing
    36. Set acc = Nothing
    37.  
    38. Exit Function
    39.  
    40. End Function
    Thanks in advance

    Shivpreet2k1








    Edit: Added [vbcode][/vbcode] tags for more clarity. - Hack
    Last edited by Hack; Dec 16th, 2005 at 07:02 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 to use dsn in vb6.0 for report

    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