Print a string variable

Print a string variable

am 22.01.2008 00:07:50 von RICHARD BROMBERG

I have a string variable that is presently being sent to a MessageBox.

I want to add a command button to the Form so I can send the string variable
directly to the printer.

Is there a simple way to do this.

Thanks

Re: Print a string variable

am 22.01.2008 01:30:33 von Rich P

The easiest way to print the value of your string variable is to create
a report which will contain the value of your string variable and just
open the report programatically. The trick is to write the content of
the string to a table which would be the recordsource for the report.
Then open the report in ViewNormal mode. That will not bring up the
report it will just print the report. Say tbl1 is the recordsource
table for Report3 and only contains one field.

Private Sub cmdOpenReport3_Click()
DoCmd.RunSql "Insert Into tbl1 Select '" & str1 & "'"
DoCmd.OpenReport "Report3", acViewNormal, , , acWindowNormal
End Sub



Rich

*** Sent via Developersdex http://www.developersdex.com ***

Re: Print a string variable

am 22.01.2008 02:45:53 von Wayne Gillespie

On 22 Jan 2008 00:30:33 GMT, Rich P wrote:

>The easiest way to print the value of your string variable is to create
>a report which will contain the value of your string variable and just
>open the report programatically. The trick is to write the content of
>the string to a table which would be the recordsource for the report.
>Then open the report in ViewNormal mode. That will not bring up the
>report it will just print the report. Say tbl1 is the recordsource
>table for Report3 and only contains one field.
>
>Private Sub cmdOpenReport3_Click()
> DoCmd.RunSql "Insert Into tbl1 Select '" & str1 & "'"
> DoCmd.OpenReport "Report3", acViewNormal, , , acWindowNormal
>End Sub
>
>
>
>Rich

Or you can write a simple function which returns the value of the string
variable and make this function the control source of a text box on the report.
No need for a table.


Wayne Gillespie
Gosford NSW Australia

Re: Print a string variable

am 22.01.2008 14:40:58 von Stuart McCall

"RICHARD BROMBERG" wrote in message
news:aB9lj.469812$kj1.246509@bgtnsc04-news.ops.worldnet.att. net...
>I have a string variable that is presently being sent to a MessageBox.
>
> I want to add a command button to the Form so I can send the string
> variable
> directly to the printer.
>
> Is there a simple way to do this.
>
> Thanks

Assuming you have a printer connected to LPT1:, you can use the following:

Dim f As Integer, msg As String

msg = "This string will be sent to the printer," & vbCrLf
msg = msg & "followed by a PageFeed character in" & vbCrLf
msg = msg & "order to eject the page from printer."
msg = msg & Chr$(12)

f = FreeFile
Open "LPT1" For Output As f
Print #f, msg
Close f