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.Thanks in advanceVB Code:
Public Function PrintAccessReport(ByVal sReportName As String) As Boolean PrintAccessReport = False On Error GoTo ErrorHandler Dim acc As Access.Application Dim db As DAO.Database Dim strDbName As String strDbName = gsDataLocation & "\" & gsDBName Set acc = New Access.Application 'acc.Visible = True Set db = acc.DBEngine.OpenDatabase(strDbName, False, False, ";PWD=yourpass") acc.OpenCurrentDatabase strDbName acc.DoCmd.OpenReport sReportName, acViewPreview acc.Application.DoCmd.PrintOut acPrintAll DoEvents acc.CloseCurrentDatabase db.Close Set db = Nothing Set acc = Nothing 'Success PrintAccessReport = 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
Shivpreet2k1
Edit: Added [vbcode][/vbcode] tags for more clarity. - Hack




Reply With Quote