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

Print button from within Outlook xp/2k3 form

Status
Not open for further replies.

rossini

Technical User
Jan 21, 2002
4
DE
Hi experts,

I am in desperate need of some advise and help from more experienced folk than me.

I am currently implementing a custom Outlook contact form that will contain a BarCode label object (BarcodeX from FathSoft). The object itself has already been integrated into the outlook form and works pretty well. Now, my plan was/is to place a custom button below that object and add some VBA code to its Click event routine. It should print the Barcode object itself either on the default windows printer or on a specifiable network printer (whatever is most easy to achieve).
Is there a way to achieve printing that single object or a bitmap graphic which has beend created from it?
Could you help me coding that (because I am totally new to this mess)?

I can imagine you are not that familiar with BarcodeX (neither am I). BarcodeX objects are activeX components which support certain methods (not sure about VBA though):

-------------
Here's what BarcodeX help file is saying:

ASP & scripting
BarcodeX control has COM interface “CbarcodeX” and it has these methods;

CreateBMP(Filename, BarcodeType, BarcodeCaption, ShowText, Width, Height, StretchMode, FontName, FontSize)
CreatePNG(Filename, BarcodeType, BarcodeCaption, ShowText, Width, Height, StretchMode, FontName, FontSize)
GetPNGStream (BarcodeType, Caption, ShowText, Width, Height, StretchMode, FontName, FontSize)

Here’s VBScript example:

Dim bc
Set bc=CreateObject("BarcodeX.CBarcodeX.1")
bc.CreateBMP "c:\bcx.bmp",0,"1234567890",1,200,100,1,"Arial",12

bc.CreatePNG "c:\bcx.png",0,"1234567890",1,200,100,1,"Arial",12

or, for out-of-memory streaming

<%
dim bc
set bc=Server.CreateObject(&quot;BarcodeX.CBarcodeX.1&quot;)
Response.ContentyType=&quot;image/png&quot;
Response.BinaryWrite bc.GetPNGStream(0,&quot;123123123&quot;,1,320,240,0,&quot;Arial&quot;,20)
set bc = Nothing
%>

....and...

Methods:

a) Copy() method

Copy a barcode picture to the clipboard in metafile format.

Syntax: object.Copy

Remarks: Use this method to copy barcode to the clipboard and use Edit->Paste command in your application to paste barcode. Barcode is in vector format, so you can resize it without losing quality.

b) CreateBMP() method

Creates a windows bitmap (.BMP) graphics file of barcode on a disk.

Syntax: object.CreateBMP(Filename as String, Width As Long, Height As Long)


Remarks: Filename should have an .BMP extension.
Width and height parameters are in device pixels.

c) PaintAt(hDC,x,y,w,h) method

Draw a barcode to a device context.

Syntax: object.PaintAt(hDc, left, top, width, height)

The PaintAt syntax has these parts:
...
object An object expression that evaluates to a BarcodeX control.
hDc A numeric expression that determines the device context's handle where the barcode will be painted.
...

Remarks: The left, top, width and height parameters are in pixels. You can use the Screen.TwipsPerPixelX and Screen.TwipsPerPixelY or Printer.TwipsPerPixelX to convert from Visual Basic's twips to device coordinates.

Visual Basic code...

Printer.Print &quot;&quot; 'initialize printer
BarcodeX1.PaintAt(Printer.hDC,500,500,3000,2000) 'paint barcode on printer
Printer.EndDoc 'close printer document

... will print barcode on default printer.
----------

The above code obviously does NOT work from within an outlook form as it is VB, not VBA....

Please help me

Oliver Rosenkranz
o.rosenkranz@estensis.de
 
I solved this problem by checking various
Here's the code to print the label via a word document template (which contains the BarcodeX activeX component)
from within an outlook form button:

----code -----
Sub cmdPrintLabel_Click

Set oWordApp = CreateObject(&quot;Word.Application&quot;)
If oWordApp Is Nothing Then
MsgBox &quot;Couldn't start Word.&quot;
Else
Dim oWordApp
Dim oWordDoc
Dim bolPrintBackground

' Open a new document
Set oDoc = oWordApp.Documents.Add(&quot;C:\Barcode.dot&quot;)

' Set the Barcode label
strMyField = Item.UserProperties.Find(&quot;KompNummer&quot;)
oDoc.FormFields(&quot;Text1&quot;).Result = strMyField

oDoc.BarcodeX1.Caption = strMyField

' If the form contains user-defined fields, you can use
' the following syntax to transfer the contents of a
' user-defined field (FieldName) to Word:
' strMyField = Item.UserProperties.Find(&quot;FieldName&quot;)
' oDoc.FormFields(&quot;Text3&quot;).Result = strMyField

' Get the current Word setting for background printing
bolPrintBackground = oWordApp.Options.PrintBackground

' Turn background printing off
oWordApp.Options.PrintBackground = False

' Print the Word document
oDoc.PrintOut

' Restore previous setting
oWordApp.Options.PrintBackground = bolPrintBackground

' Close and don't save changes to the document
Const wdDoNotSaveChanges = 0
oDoc.Close wdDoNotSaveChanges

' Close the Word instance
oWordApp.Quit

' Clean up
Set oDoc = Nothing
Set oWordApp = Nothing
End If
End Sub
---- end code ---

It works only for my local prointer though.
When I change the oWordApp.ActivePrinter value
then my Default printer changes, but I cannot
open the word template any longer....

Damn... any help with changing the default printer
prior to printing to a network printer, then print, then reload the original setting???

Oliver Rosenkranz
o.rosenkranz@estensis.de
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top