Send file to pinter

Brian1960

Brian1960
Local time
Today, 21:48
Joined
Aug 13, 2004
Messages
141
I have an access database which creates an HTML message body and sends the message as an email. This code runs through a loop in a recordset, but if there is no email address I'd like to outpout the message to a printer. I can create the html fine with
...
Set objFso = New FileSystemObject
Dim objFile As Object
Set objFile = objFso.OpenTextFile("K:/output/Bk" & Me.RefID & "-" & StrLoopName & ".htm", 8, True)
objFile.WriteLine txtMessage
objFile.Close
Set objFile = Nothing
Set objFso = Nothing
...
This works fine and creates the html perfectly. BUT How do I then print that file.
Is there some thing like
objFSO.CopyFile source, printer

if so does anyone have the syntax.

Thanks
:confused:
 
how do you want it printed?? assuming you are sending raw text to a local printer you could use:

Set objFso = New FileSystemObject
Dim objFile As Object
Set objFile = objFso.OpenTextFile("K:/output/Bk" & Me.RefID & "-" & StrLoopName & ".htm", 8, True)
objFile.WriteLine txtMessage
objFile.Close
Set objFile = Nothing
Set objFso = Nothing

Open "LTP1" For Output As #1
Print #1, txtmessage
Close #1


otherwise you should just make a report and use

DoCmd.OpenReport
 
You can try the following:

Code:
a = shell("K:/output/Bk" & Me.RefID & "-" & StrLoopName & ".htm")
SendKeys "^P"  ' Control-P (to print)
Application.Wait Now() + TimeValue("0:00:05")
SendKeys "%FC" ' Alt-F-C (to close)

If you are not using IE as your browser, you may have to modify the SendKeys commands appropriately to print and close the application.


Treason:
Code:
Open "LTP1" For Output As #1
Print #1, txtmessage
Close #1
The only problem with this is that it will print the HTML tags too...
 
Avoid SendKeys.

This is the variation of the ShellExecute API I use to open or print a file...

Code:
Option Compare Database
Option Explicit

Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Public Function Test()
On Error GoTo Err_Test

    'Open file
    ShellExecute 0, "Open", "C:\Temp\123.txt", "", "", 1

    'Print file
    ShellExecute 0, "Print", "C:\Temp\123.txt", "", "", 0
    
    'Execute an executable
    ShellExecute 0, "Open", "C:\Temp\123.bat", "", "", 0

Exit_Test:
    Exit Function

Err_Test:
    MsgBox Err.Number & " - " & Err.Description
    Resume Exit_Test

End Function
 
I am wholely unfamiliar with the Windows API - I knew there was probably a better way, but I didn't know it! :)

Can anyone recommend a good site / resource for Windows API?
 
In my opinion the best way to learn APIs are through the C programming language. But look for any Windows 32 Programming API, Windows Application Programming, or Application Programming Interface books
 
Thanks

Thanks for the help.
Treason - Yours works fine for text only but this is an HTM document.
TPKStock - Yes HTML tags get printed, with Traeson's the send keys bit is an option, but ugly.
GHudson - API looks perfect and I'll try it it.

I, of course cheated, and used Word.

If CheckWord() = 0 Then
Set Wrd = CreateObject("Word.Application")
Else
Set Wrd = GetObject(, "Word.Application")
End If
Wrd.Visible = False
Wrd.Documents.Open strHTMLName
Wrd.ActiveDocument.PrintOut
Wrd.ActiveDocument.Close 0

The actual event round why I do thois is that I send an HTML based email to several contacts. It loops through the recordset and cahnegs lines in the HTML. If there is no email address then it prints out instead.

AS my old IT Professor used to say, not very elegant, but it works all the time. I like GHudson's version.

Thanks all.
 

Users who are viewing this thread

Back
Top Bottom