Share via

UseDefaultPrinter throwing Automation Error

Anonymous
2022-10-03T16:54:12+00:00

Need code in front end to strip printer saved with a form.

I have tried using the UseDefaultPrinter but receive

I can use the following code and it returns false.

Msgbox Me.UseDefaultPrinter

I can't use the following code to set the value to true.

Me.UseDefaultPrinter = True

or

Dim f as Form

Set f = Forms("test")

With f

.UseDefaultPrinter = True

End With

Any ideas?

Regards,

L.

Microsoft 365 and Office | Access | For business | Other

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Anonymous
    2022-10-04T15:22:26+00:00

    Thanks Tom.

    I believe I am satisfying your suggestion.

    The form is open and contains a Command Button for Printing. Here is the form section (it is a parent form) containing the Command Button.

    The code that launches is typical.

    Private Sub PrintOnly_Click()

    On Error GoTo Err_PrintOnly_Click

    DoCmd.PrintOut , , , , 1

    Exit_PrintOnly_Click:

    Exit Sub 
    

    Err_PrintOnly_Click:

    MsgBox Err.Description 
    
    Resume Exit\_PrintOnly\_Click 
    

    End Sub

    It is in this procedure I am attempting to force the application to use the default printer for the desktop where the front end is running.

    Desired code example to reside in event procedure.

    If Me.UseDefaultPrinter = False Then

    Me.UseDefaultPrinter = True

    Me.Printer.ColorMode = acPRCMMonochrome 
    

    End If

    OR

    Forms("test").UseDefaultPrinter = True

    Regards,

    L

    Was this answer helpful?

    0 comments No comments
  2. Tom van Stiphout 40,211 Reputation points MVP Volunteer Moderator
    2022-10-04T14:46:59+00:00

    The forms collection only includes open parent forms. So if you first open your "test" form, the code will work.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2022-10-04T14:42:04+00:00

    Dear Lance James,

    Good day! Thank you for posting in Microsoft Community.

    We would love to help you on your code query, considering our team focuses on general and build-in query, for example, installation and activation issue of Office, and your query is about using code to in Access, we sincerely recommend you go to Stack Overflow Community along with any other relevant tags as there are also many experienced engineers and experts in the forums there. 

    Disclaimer: Microsoft provides no assurances and/or warranties, implied or otherwise, and is not responsible for the information you receive from the third-party linked sites, or any support related to technology. 

    At the same time, we will also keep this thread open, so other Community members and Experts can also share their suggestions and inputs. 

    Thank you for your cooperation and understanding! Hope you keep safe and healthy always.

    Sincerely,

    Tina | Microsoft Community Moderator

    Was this answer helpful?

    0 comments No comments