Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing without using reports 1

Status
Not open for further replies.

zakrocz

Programmer
Feb 12, 2003
14
GB
Hi,

In Visual Basic I can print directly to the printer with the following code

Printer.Print "This code will print this text"

Can someone tell me if there is equivalent code to do the same in VBA?

Thanks

Ronnie
 
zakrocz:

Use the OpenReport method of the DoCmd. The code should look like:

DoCmd.OpenReport "Name of Report", acNormal

HTH,

Vic
 
Thanks for the reply, but it doesn't answer my question.

I want to do my own printouts using VBA code, NOT use Access Reports.

I've done it in VB, but I'm coming to the conclusion after 2 days of forum searching, web searching, PC World Books, library etc etc that VBA does not offer this option.

This is so straightforward in VB, but it looks like VBA doesn't do printing.
 
zakrocz:

When you say "from VBA", I'm not sure what you mean. Do you mean, you are in Access, or some other MS app and want to print a report that's already designed in an Access db?

Or do you mean you want to be able to design a complete report in VBA?

Vic
 
I think what zakrocs is trying to do is use the printer like a debug.print thing so instead of printing to the debug window, you get hard copies of your debug messages.

Is that what you meant?

AFAIK, there is no way to do this directly from VBA, you may be able to find an activex control that does it, but other than that...


As a workround, you could use word to print your message:

Sub PrintMessage(strMessage As String)
Dim wd As Object
Dim doc As Object

Set wd = CreateObject("Word.Application")
Set doc = wd.Documents.Add

wd.Selection.TypeText Text:=strMessage

wd.PrintOut
doc.Close False
Set doc = Nothing
wd.Quit False
Set wd = Nothing
End Sub


Just call it with:
PrintMessage "This code will print this text"

HTH

Ben
----------------------------------------
Ben O'Hara
----------------------------------------
 
Yep, I was trying to print just one record from a table directly from VBA code, but it does seem it is not possible.

So I guess I better get to grips with Access reports and hopefully it will allow me to achieve the result I'm looking for. It's a bit more involved than printing fields from one record, in case you were wondering why I was attempting to code it rather than use a simple Access report to do the job.

I was hoping to code it to get the job done asap, my client awaits, but they'll just have to wait some more.

Thanks for the replies :)
 
This doesn't work on my system, but maybe it will work on yours:


Sub TestPrint()
Dim MyHandle As Integer
MyHandle = FreeFile
Open "PRN:" For Append As MyHandle
Print #MyHandle, "DUH!" & vbCrLf
Close MyHandle
End Sub

other names like "PRN", "LPT1", "LPT1:" may work

HTH
 
Hey beetee, it works!! Great stuff.

Thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top