I can't save after "Set specific printer to a report" (1 Viewer)

nam0812

New member
Local time
Today, 14:30
Joined
Mar 12, 2020
Messages
5
Hello
my application access has a report name "RpKQNS"
In a form i made a combobox "CboPrinters" to change printer for report "RpKQNS"
but it can't be saved. There are no change in "The printer for that report"
Anyone has idea
Thanks in advance

Here the vba code

Code:
Private Sub FillPrinterList(ctl As Control)
    Dim prt As Printer
    ctl.RowSourceType = "Value List"
    For Each prt In Application.Printers
       ctl.AddItem prt.DeviceName
    Next prt

End Sub

Code:
Private Sub Form_Load()

    Call FillPrinterList(Me.CboPrinters)
    On Error Resume Next
    Me.CboPrinters = Application.Printer.DeviceName
End Sub

Code:
Private Sub CboPrinters_AfterUpdate()

    Dim prts As String
    prts = Me.CboPrinters.Value
    DoCmd.OpenReport "RpKQNS", acViewDesign, , , acHidden
    Set Reports(RpKQNS).Printer = Application.Printers(prts)
    DoCmd.Close acReport, "RpKQNS", acSaveYes


End Sub
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 00:30
Joined
Oct 29, 2018
Messages
21,358
Hi. Welcome to AWF!

Are you getting any error messages or a warning prompt to confirm before saving the design changes?
 

nam0812

New member
Local time
Today, 14:30
Joined
Mar 12, 2020
Messages
5
Hi
theDBguy

There are no error messages or a warning. It can change printer but no saved in report
 

Isaac

Lifelong Learner
Local time
Today, 00:30
Joined
Mar 14, 2017
Messages
8,738
Here is a very helpful bit of code from Microsoft, which makes it appear that you should set your report object after opening the report in design view, and should leverage the .PrtDevNames property instead.

 

nam0812

New member
Local time
Today, 14:30
Joined
Mar 12, 2020
Messages
5
Hi Isaac
I want to user can set specific printer for a report
 

Isaac

Lifelong Learner
Local time
Today, 00:30
Joined
Mar 14, 2017
Messages
8,738
Hi Isaac
I want to user can set specific printer for a report
Yes, that is what I understood. Hopefully that Microsoft post can give you a path forward.
 

Isaac

Lifelong Learner
Local time
Today, 00:30
Joined
Mar 14, 2017
Messages
8,738
I am not sure if this will work, but you can try it.
Code:
Private Sub CboPrinters_AfterUpdate()

    Dim prts As String, rpt as Report
    prts = Me.CboPrinters.Value
    DoCmd.OpenReport "RpKQNS", acViewDesign
    Set rpt = Reports("RpKQNS")
    rpt.PrtDevNames = prts
    DoCmd.Close acReport, "RpKQNS", acSaveYes

End Sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:30
Joined
May 7, 2009
Messages
19,169
on old MSA version, probably worked before.
unfortunately, now it doesn't.

you can still achieve what you need, switching different printer
on different report.

first create a New table (tblReportPrinter):

ReportName (short text, 100)
PrinterName(short text, 100)

change the Combo's AfterUpdate event:
Code:
Private Sub CboPrinters_AfterUpdate()
    If DCount("1", "tblReportPrinter", "ReportName='RpKQNS'") > 0 Then
        CurrentDb.Execute "Update tblReportPrinter " & _
            "Set PrinterName='" & Me.cboPrinters & "' Where ReportName='RpKQNS';"
    Else
        CurrentDb.Execute "Insert Into tblReportPrinter (ReportName, PrinterName) " & _
            "Select 'RpKQNS', '" & Me.cboPrinters & "';"
    End If
End Sub

add code to 'RpKQNS report's Activate and Close event:
Code:
Private Sub Report_Activate()
    If DCount("1", "tblReportPrinter", "ReportName='" & Me.Name & "'") > 0 Then
        Set Application.Printer = Application.Printers(DLookup("PrinterName", "tblReportPrinter", "ReportName='" & Me.Name & "'"))
    End If
End Sub

Private Sub Report_Close()
    Set Application.Printer = Nothing
End Sub
 

Isaac

Lifelong Learner
Local time
Today, 00:30
Joined
Mar 14, 2017
Messages
8,738
that changes the default printer for the entire application which I would have suggested but that is not what the Op wanted. He wanted it per report...
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:30
Joined
May 7, 2009
Messages
19,169
I am not sure if this will work, but you can try it.
i don't believe you did not try it.
 

nam0812

New member
Local time
Today, 14:30
Joined
Mar 12, 2020
Messages
5
Thanks arnelgp. Your code worked.
I also found that "Has Module" property of RpKQNS is yes. My code worked in other report with "Has Module" No
 
Last edited:

Users who are viewing this thread

Top Bottom