PDA

Click to See Complete Forum and Search --> : Help to use dsn in vb6.0 for report


SHIVPREET2K1
Dec 16th, 2005, 12:46 AM
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.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 FunctionThanks in advance

Shivpreet2k1








Edit: Added tags for more clarity. - Hack

Hack
Dec 16th, 2005, 08:27 AM
Moved to reporting section.