Print contents of text box

Folks,
I have a form with a text box (txtSolution) that lists the step-by-step instructions to complete a task.
On this form I have a command box that allows the user to print out the contents of the list box. What sub procedure code do I need to print out the contents of the text box (no print preview is necessary)?

Sub PrintSolution()

End Sub
Frank FreeseAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steven HarrisPresidentCommented:
I look forward to some Experts chiming in on this one, I have never had the need to print from VBA in this way (yet)!

As an alternative, you could create a new sheet and expand a cell (A1) to page size.  Put the text for your Text box in this cell, then change your ControlSource property to that cell.  Name the sheet, hide it and then add the following to the button:

Sheets("SheetName").PrintOut

Open in new window


Hopefully we can get byundt and/or MartinLiss in here, I am sure they will have a solution!
0
Frank FreeseAuthor Commented:
I haven't seen anything, yet, in my search. Let's see who else chimes in also
0
Martin LissOlder than dirtCommented:
Printer.Print txtSolution.text
Printer.EndDoc
0
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Frank FreeseAuthor Commented:
Martin,
I'll try this today and with l the confidence in you I'll bet it'll work.
You make some of this so easy. I searched for a Internet solution and this did not show up.
0
Frank FreeseAuthor Commented:
Martin,
I used your code and got run-time error.  See below:
RUN TIME ERROR
Code used in Sub
0
NorieAnalyst Assistant Commented:
fh_freeze

Printer.Print is for VB, not VBA.

If you want to print the contents of a textbox on a userform you could transfer the contents to a blank sheet, set up the page and then print.

Here's an example of that.
Private Sub CommandButton1_Click()
Dim strContents As Variant
Dim wsTemp As Worksheet

    strContents = Split(Me.TextBox1, Chr(10))
    
    Set wsTemp = Worksheets.Add
    
    wsTemp.Range("A1").Resize(UBound(strContents)).Value = Application.Transpose(strContents)
    
    ' code to set sheet up for printing
    
    wsTemp.PrintOut
    
    Application.DisplayAlerts = False
    wsTemp.Delete
    Application.DisplayAlerts = True
    
End Sub

Open in new window


If you want to print the userform you can use Me.PrintForm.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Martin LissOlder than dirtCommented:
imnorie is right. I forgot where I was.
0
Frank FreeseAuthor Commented:
let me try the me.printform
0
Frank FreeseAuthor Commented:
OK...got what I needed from imnorie
thanks everyone
0
Frank FreeseAuthor Commented:
thanks to all
Much appreciated
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.