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.
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?
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.
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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.