Externally trigger report, print and close

510sx

Registered User.
Local time
Yesterday, 22:34
Joined
Apr 26, 2006
Messages
12
I thought I could figure it out by myself, but after I spent a few nights, I am kind of exhausted.

I created a report and dragged to my c drive (c:\myreport.mar). If I double click the mar file, it will display the report nicely. My main problem is; I need this report to be executed 3 times a day and automatically print it and close it. The access program will be closed most of the time.

Have you guys done something like this or similar? I don't mind using vbs, macro or bat file. Please guide me to the right direction.
 
Hi Friend

Try this module in vb6.0


_____________



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
'strDbName = gsDataLocation & "\" & gsDBName
strDbName = App.Path & "\urdatabase.mdb"
acc.Visible = True
Set db = acc.DBEngine.OpenDatabase(strDbName)
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




__________


do this coding of timer or command button

where ever u want


for example


sub command1_Click()

dim ph as boolean

ph=printaccessreport("URREPORTNAME")



End sub

___________

you have to add the reference of dao library and ms access library in vb 6.0

and this will work. i have tes it many many times

regards

Shiv Preet
 

Users who are viewing this thread

Back
Top Bottom