PDA

View Full Version : [SOLVED:] PrintForm opens a 'greyed out' UserForm1



paulked
10-31-2017, 03:56 AM
Hi all

I have a userform that I want to print out. However, when I use .PrintForm another userform (UserForm1) opens and I cant close it!

Before code:
20813
Run this:

Private Sub CommandButton6_Click()
On Error Resume Next
OnSiteForm.PrintForm
End Sub

After execution:
20814

The blank UserForm1 that has appeared cannot be closed!

There is no code associated with the OnSiteForm so what is going on?

Best regards

Paul Ked

snb
10-31-2017, 05:00 AM
I'd use:


Private Sub UserForm_Click()
Me.PrintForm
End Sub

paulked
10-31-2017, 05:51 AM
Thanks for that, it does work but the user has to click on a point on the form that is clear of any controls.

I'll try to loop through all controls and images so that the user can click anywhere (may need some help a bit later!)

Cheers :beerchug:

Jan Karel Pieterse
10-31-2017, 06:12 AM
I expect exchanging OnSiteForm.PrintForm with Me.PrintForm in your existing code should also work?

paulked
10-31-2017, 06:43 AM
Thanks Jan, but the OnSiteForm.PrintForm command is called from a button on another form without the OnSiteForm being opened.

For the Me.PrintForm to work I have to open it and then get the user to print it. There are a lot of controls on the form so picking a place to click is quite cumbersome.

paulked
10-31-2017, 06:55 AM
I've sorted it by Setting the ShowModal to false on the OnSiteForm and then:


Private Sub CommandButton6_Click()
On Error Resume Next
OnSiteForm.Show
Application.Wait (Now + TimeValue("0:00:01"))
OnSiteForm.PrintForm
Application.Wait (Now + TimeValue("0:00:01"))
OnSiteForm.Hide
End Sub


Many thanks all.

paulked
10-31-2017, 08:31 AM
That didn't last long, it's doing it again so I've re-opened the thread!

I have re-booted and only run Excel and written the attached test.

20817

If you print the UserForm2 (Me.PrintForm) it works fine.

But if you print the UserForm1 (UserForm1.PrintForm) the ghost appears!

Anyone else see this? Or is it something on my system?

Best regards

Paul Ked

Jan Karel Pieterse
10-31-2017, 08:54 AM
Use an object variable for the other form:


Private Sub CommandButton1_Click()
Dim uForm As UserForm1
Set uForm = New UserForm1
Me.Hide
uForm.Show vbModeless
uForm.PrintForm
Unload uForm
Set uForm = Nothing
Me.Show
End Sub

paulked
10-31-2017, 09:17 AM
Brilliant, thank you!

:thumb