Print reports from VBA

Birdman895

Registered User.
Local time
Today, 13:32
Joined
Apr 19, 2012
Messages
62
Can you send a report directly to the printer?
We have Clients with multiple Contact Notes, by multiple Clinicians, each of these are separate tables. Every month we print two reports for each client that had at least one contact in that date-range. Usually 200 clients, takes a lot of time.
My approach so far is a query within a make-table query to get a list of unique client ID's that had one contact in the date-range. Then I use that table in code to create a recordset, use a Do Loop within that where I print the two reports for the 1st client, move to next record and loop. Now that I've got it working I'm not sure how to print all the reports:)
My 1st question, can you send a report directly to the printer from code? The printer is a networked Konica Minolta Biz-hub so I think it can handle that many jobs being queued that fast.
is there a different way to do this?
Thanks
 
A better way would be to build a report based off your new query that limits the clients.

Or another way without having to reinvent your entire report would be to build your reports query with an inner join between your reports dataset and your query that limits clients, this would return only those that are in your query.

Without seeing your database I'm not sure if either of these solutions are possible, but something to think about.
 
This doesn't work for this. It doesn't print a header and footer for each client, just the "Header- All client records- Footer.
I have these two reports that are printed at end-o-month for each client. They are actually controlled documents. One of them has three sub-forms and the other one has two. I need them to print exactly as formatted for each client, and then move to the next clientID. That is why I went down this path of - print both reports and Loop to next.
This is the code that I have so far. Can I send the two reports to the printer from code, avoiding PrintPreview etc.?

Private Sub Preview_Click()
On Error GoTo Err_Preview_Click

Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim Client As Long
If IsNull([Beginning Date]) Or IsNull([Ending Date]) Then
MsgBox "You must enter both beginning and ending dates."
DoCmd.GoToControl "Beginning Date"
Else
If [Beginning Date] > [Ending Date] Then
MsgBox "Ending date must be greater than Beginning date."
DoCmd.GoToControl "Beginning Date"
Else

Me.Visible = False
DoCmd.OpenQuery "ContactNoteEOM_tem" ' (a MakeTable query that creates table ContactNoteEOM_temp)

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("ContactNoteEOM_temp", dbOpenSnapshot)

' Loop through the recordset, processing rows
Do Until rst.EOF
TempVars.Add "Client", rst!ClientID.Value
Client = rst!ClientID.Value ' (used in a query and both report calls)
DoCmd.SetWarnings False
DoCmd.OpenReport "ContactNote2_EOM", acViewPreview, , "[ClientID]=" & rst!ClientID.Value
DoCmd.OpenReport "ContactNote3_EOM", acViewPreview, , "[ClientID]=" & rst!ClientID.Value
DoCmd.SetWarnings True
rst.MoveNext
Loop

End If
End If

TempVars.RemoveAll
Set dbs = Nothing

Exit_Preview_Click:
Set dbs = Nothing
Exit Sub
Err_Preview_Click:
MsgBox Error$
Resume Exit_Preview_Click

End Sub
 
Just take out the "acViewPreview"

Default is to just print the report to the default printer.
 
Duh!
I just knew it was something obvious & simple.
Thank you
 

Users who are viewing this thread

Back
Top Bottom