dbTalk Databases Forums  

Print a string variable

comp.databases.ms-access comp.databases.ms-access


Discuss Print a string variable in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
RICHARD BROMBERG
 
Posts: n/a

Default Print a string variable - 01-21-2008 , 05:07 PM






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


Reply With Quote
  #2  
Old   
Rich P
 
Posts: n/a

Default Re: Print a string variable - 01-21-2008 , 06:30 PM






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 ***

Reply With Quote
  #3  
Old   
Wayne Gillespie
 
Posts: n/a

Default Re: Print a string variable - 01-21-2008 , 07:45 PM



On 22 Jan 2008 00:30:33 GMT, Rich P <rpng123 (AT) aol (DOT) com> wrote:

Quote:
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


Reply With Quote
  #4  
Old   
Stuart McCall
 
Posts: n/a

Default Re: Print a string variable - 01-22-2008 , 07:40 AM



"RICHARD BROMBERG" <noreply (AT) att (DOT) net> wrote

Quote:
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




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.