Printing from VBA

  • Thread starter Thread starter zulander
  • Start date Start date
Z

zulander

Hi, i am having problem printing a text to the printer. it print's but
only one line.
this is my function, thnak you


Public Function PrintTo(deviceindex As Integer, txt As String) As Long
Dim DocIn As DOCINFO
Dim xhdc As Long
Dim xOut As String


Dim splitLine() As String

xhdc = CreateDC(Access.Printers(deviceindex).DriverName,
Access.Printers(deviceindex).DeviceName, 0, 0)
Find_XY = Set_XY(xhdc)

DocIn.cbSize = Len(DocIn)
DocIn.lpszDocName = "Generator Inventory"
DocIn.lpszDatatype = vbNullString

DocIn.lpszOutput = vbNullString
xOut = Rectangle(xhdc, 10, 10, 1000, 150)
xOut = StartDoc(xhdc, DocIn)
xOut = StartPage(xhdc)

splitLine = Split(txt, vbCrLf)

For i = LBound(splitLine) To UBound(splitLine)

xOut = TextOut(xhdc, 0, 0, splitLine(i), Len(splitLine(i)))
Next

xOut = EndPage(xhdc)
xOut = EndDoc(xhdc)
GetHdc = DeleteDC(xhdc)
End Function
 
And why isn't this in a report? It seems like you're trying to do a VB
function is a place where it's not necessary.
 
I don't know why you are not simply using a report bound to the Recordset
you are using. Anyhow, here is the relevant excerpt from the relevant MSDN
page:

By default, the current position is not used or updated by this function.
However, an application can call the SetTextAlign function with the fMode
parameter set to TA_UPDATECP to permit the system to use and update the
current position each time the application calls TextOut for a specified
device context. When this flag is set, the system ignores the nXStart and
nYStart parameters on subsequent TextOut calls.


--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
Back
Top