Xprint and Multiple buttons

L

Lutiana

Hi all, I am new at customizing outlook forms and I am having an issue
with trying to have multiple print buttons on a form.

I am trying to create a form that will allow me to print 2 kinds of
things. One is an internal doc for our filing and the other is one for
our customer (these do not need to be printed at the same time, nor do
I think they ever would be).

I am using xprint and I am trying to extrapolate from the MS example
how to do this. If I use just one button it works fine, but as soon as
I try to add another I get an error message (after the option to
debug).

Error 1: Object doesn't support this property or method:
'objPage2.Xprint2' Line No. 17

Then when I click the button I get: Object required: 'objXprint2'

I cannot seem to find any information anywhere on this, and as near as
a I can see the code is complete.

Here is my code:

Dim objInsp
Dim objPage1, objPage2
Dim objXPrint1, objXPrint2

Function Item_Open()
Set objInsp = Item.GetInspector
Set objPage1 = objInsp.ModifiedFormPages("RMA Entry")
Set objXPrint1 = objPage1.XPrint1
objXPrint1.Preview = True
objXPrint1.Controls = objPage1.Controls
End Function

Function Item2_Open()
Set objInsp = Item.GetInspector
Set objPage2 = objInsp.ModifiedFormPages("PrintReport")
Set objXPrint2 = objPage2.XPrint2
objXPrint2.Preview = True
objXPrint2.Controls = objPage2.Controls
End Function

Sub cmdPrint_Click()
objXPrint1.PrintForm
End Sub

Sub cmdPrintReport_Click()
objXPrint2.PrintForm
End Sub


Any help would be greatly appreciated.

Thanks

J
 
S

Sue Mosher [MVP-Outlook]

There is no Item2_Open event handler, only Item_Open. All the code you want to run when the item opens in its form must go there.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
L

Lutiana

Thanks for the response,

Ok, so I remove that, and made the code as follows:

---------------------------------------------------------------------------
Dim objInsp
Dim objPage1, objPage2
Dim objXPrint1, objXPrint2

Function Item_Open()
Set objInsp = Item.GetInspector
Set objPage1 = objInsp.ModifiedFormPages("RMA Entry")
Set objXPrint1 = objPage1.XPrint1
objXPrint1.Preview = True
objXPrint1.Controls = objPage1.Controls

Set objInsp = Item.GetInspector
Set objPage2 = objInsp.ModifiedFormPages("PrintReport")
Set objXPrint2 = objPage2.XPrint2
objXPrint2.Preview = True
objXPrint2.Controls = objPage2.Controls
End Function

Sub cmdPrint_Click()
objXPrint1.PrintForm
End Sub

Sub cmdPrintReport_Click()
objXPrint2.PrintForm
End Sub

---------------------------------------------------------------------------

Now I get the following error:

Object required: 'objPage2' Line no 14

and when I click on the second button I get:

Object required : 'objXprint2'

I don't get it, these are objects that are declared the same as
objXprint1 and objPage1

What am I doing wrong?
 
S

Sue Mosher [MVP-Outlook]

For one thing, the proper way to instantiate an object for an Outlook custom form would be:

Set objPage2 = objInsp.ModifiedFormPages("PrintReport")
Set objXPrint2 = objPage2.Controls("XPrint2")

But more importantly, did you double-check the name of the page for typos?

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
L

Lutiana

The page is spelt correctly. I shortened it to simply "Print" to make
sure.

Still the same thing, Object required 'objPage2" even after I made the
changes so that I was using the "proper wat to instantiate and object"

The thing that makes no sense to me is that objXprint1 works just fine
and logically if I replicate the same thing it should work. The only
think I have changed is that the 1 is a 2 to try an instantiate a
second similar object, but this is not happening and I apparently lack
the knowledge to know why...

This defies logic and is very frustrating. Thank you for the help.

My code is now:
------------------------------------------

Dim objInsp
Dim objPage1, objPage2
Dim objXPrint1, objXPrint2

Function Item_Open()
Set objInsp = Item.GetInspector
Set objPage1 = objInsp.ModifiedFormPages("RMA Entry")
Set objXPrint1 = objPage1.XPrint1
objXPrint1.Preview = True
objXPrint1.Controls = objPage1.Controls

Set objInsp = Item.GetInspector
Set objPage2 = objInsp.ModifiedFormPages("Print")
Set objXPrint2 = objPage2.Controls("XPrint2")
objXPrint2.Preview = True
objXPrint2.Controls = objPage2.Controls
End Function

Sub cmdPrint_Click()
objXPrint1.PrintForm
End Sub

Sub cmdPrintReport_Click()
objXPrint2.PrintForm
End Sub

----------------------------------------------------
 
S

Sue Mosher [MVP-Outlook]

I don't know what the problem is either. The symtoms still point to this statement being the problem:

Set objPage2 = objInsp.ModifiedFormPages("Print")

I bet if you add this code, it will indicate that you're getting Nothing back:

If objPage2 Is Nothing then
MsgBox "no Print page"
End If

Note that you don't need two Set objInsp statements in the same procedure.

FWIW, XPrint has a lot of limitations.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
L

Lutiana

I think I agree that the problem is with:

Set objPage2 = objInsp.ModifiedFormPages("Print")

And when I implement the code you said I indeed am getting nothing
back. But what I don't get it, limited or not I should be able to
instantiate as many variables (objPages) as I want with the objInsp
(well as many as memory would allow). The statement above has nothing
to do with Xprint doesn't it?

So the logically question is what would be better to use to print
custom forms exactly as they are seen on the screen?

Thanks again for you're time.
 
S

Sue Mosher [MVP-Outlook]

The statement has everything to do with XPrint, since you cannot use XPrint's methods without having a reference to that control and you can't get the control without the page.

I'm still think there's a typo in the page name. Even a trailing space could be the culprit.

I use Word templates or HTML methods for printing all my custom forms, never XPrint, which isn't even supported in versions past Outlook 2000. See http://www.outlookcode.com/d/customprint.htm

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top