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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best way to print Reports and Invoice 1

Status
Not open for further replies.

JohnStep

Programmer
Apr 19, 2000
190
US
What is a VB coders best option on Printing Reports and Invoices Crystal Reports or?? Any Ideas?
 
Well, depending on their complexity you could possibly use the data report inside of VB. However, there is any level of complexity to them at all you will save yourself a headache if you just use Crystal Reports.
 
IMHO VBs Data Report will be good enough... but if u'd be using the all impact printer might as well not to use data report nor crystal, else print directly to the printer...


.
.

eg..

fSendToPrinter "LPT1", "SOME TExT"


Public Function fSendToPrinter(vPrinter As String, vString As String) As Boolean
Static mFreeFile
On Error Resume Next
vPrinter = UCase(vPrinter)
mFreeFile = FreeFile()
If vPrinter Like "LPT*" Or vPrinter Like "COM*" Then
Open vPrinter For Output As #mFreeFile
Else
Open vPrinter For Append As #mFreeFile
End If
Print #mFreeFile, vString
Close #mFreeFile
fSendToPrinter = True
On Error GoTo 0
End Function

or.....


fSendToPrinter "TEMPFILE.TXT", "SOME TExT"
fSendToPrinter "TEMPFILE.TXT", "SOME TExT"
fSendToPrinter "TEMPFILE.TXT", "SOME TExT"
fSendToPrinter "TEMPFILE.TXT", "SOME TExT"

fSendFileToPrinter "LPT1", "TEMPFILE.TXT"

Public Function fSendFileToPrinter(vFilename As String, vPrinter As String) As Boolean
Static fSys As New Scripting.FileSystemObject
Static F As TextStream
Static mString As String
On Error Resume Next
If Dir(vFilename) <> "" Then
Set F = fSys.OpenTextFile(vFilename, ForReading)
mString = F.ReadAll
Set F = Nothing
Set fSys = Nothing
fSendFileToPrinter = fSendToPrinter(vPrinter, mString)
Else
fSendFileToPrinter = False
End If
End Function

Public Function fReadFile(vFilename As String) As String
On Error Resume Next
Dim fSys As New Scripting.FileSystemObject
Dim F As TextStream
Set F = fSys.OpenTextFile(vFilename, ForReading)
fReadFile = F.ReadAll
Set F = Nothing
Set fSys = Nothing
On Error GoTo 0
End Function

Public Function fSendToPrinter(vPrinter As String, vString As String) As Boolean
Static mFreeFile
On Error Resume Next
vPrinter = UCase(vPrinter)
mFreeFile = FreeFile()
If vPrinter Like "LPT*" Or vPrinter Like "COM*" Then
Open vPrinter For Output As #mFreeFile
Else
Open vPrinter For Append As #mFreeFile
End If
Print #mFreeFile, vString
Close #mFreeFile
fSendToPrinter = True
On Error GoTo 0
End Function
 
rmnastros:
Code:
    Static fSys As New Scripting.FileSystemObject
    Static F As TextStream
    Static mString As String
Why do you have these as static? I don't get it.

TIA

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top