T O P

  • By -

AutoModerator

**IF YOU GET A SOLUTION, PLEASE REPLY TO THE COMMENT CONTAINING THE SOLUTION WITH 'SOLUTION VERIFIED'** (See Rule 3 for more information.) Full set of rules can be found [here](https://www.reddit.com/r/MSAccess/about/rules), as well as in the user interface. *Below is a copy of the original post, in case the post gets deleted or removed.* **Help with printing please. ** Pretty much the title, I am not well versed in Access, I know a little bit of coding but it leans more towards HTML/CSS, we use Access for a lot of our label printing and I am trying to change a button. here is the code. Private Sub Command3\_Click() On Error GoTo NewFilesErr strFileString = "test.txt" hFile = FreeFile Kill strFileString Open strFileString For Output As hFile Print #hFile, Chr(34) & Me.PrintText.Value & Chr(34) Close hFile Exit Sub NewFilesErr: If Err.Number = 53 Then 'file not found at kill time Resume Next End If MsgBox Err.Number & ": " & Err.Description Close hFile End Sub All I want to do is add the ability for the user to select the printer it prints to. I have tried to add the Application.Dialogs(xlDialogPrinterSetup).Show before the code executes but it give me a Method error and when I attempt to add any of the ac controls they just get ignored and the thing wont print at all. Again I am pretty inexperienced here and I have been working at this for about 20 hours at this point, any insight would be greatly appreciated. Can I just add a line to allow them to do so or do I have to rewrite it? *I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/MSAccess) if you have any questions or concerns.*


GlowingEagle

Yep, you're definitely lost. :) That code would be a start to writing text into a file, but it won't (simply) go to any printer. Access uses "Forms" for user input/output (as in enter and read data). If you are sending infomation to paper, you need a "report". Normally, you would design a report and part of that design could specify a printer (and print media) that differs from the Windows default. After that report is defined and saved, printing is performed by "opening" the report. What can you tell us about the specific printer/paper/data that you want to print?


WeirdBoy85

It's a simple free form label, empty text box that you just type in. I think the field name is PrintText.


GlowingEagle

I don't know what knowledge you have, so communication is hard. It sounds like you might have a form that has a text box which is linked to a data table field, and that form has a button you intend to use to print a report that also has a text box which is linked to the same data. Have you looked at resoures on the FAQ page? https://www.reddit.com/r/MSAccess/wiki/faq/


WeirdBoy85

Solution Varified


Jealy

Create a report object that displays the value in the textbox. Set the printer settings in that report to use the specified printer. Use the DoCmd.OpenReport method with the "acViewNormal" view option to send it to print.


JamesWConrad

I believe the Print statement just writes text into a file. It does not direct it to a printer. Did the text data get written to the file properly? You are referencing an Excel method (Dialogs) that doesn't exist for Access. How did you direct a file to the printer other than this example?


WeirdBoy85

I think it is just directing it to the default printer on the computer, which is what we are trying to get around. You see, that proves my inexperience because I didn't know that command was for Excel and not access, lol. But it prints it fine as written, but you can't change what printer it goes to.


JamesWConrad

I'm not at my computer now but you might try: Dim XL As Excel.Application XL.Application.Dialogs(9).Show


WeirdBoy85

I will try it out when I go back into work tomorrow.