One Works the Other Doesn't

  • Thread starter Thread starter DS
  • Start date Start date
D

DS

How come one works, This One

Set Application.Printer = Application.Printers(Me.Text0.Column(1))
DoCmd.OpenReport "Days"
Set Application.Printer = Nothing


But this one doesn't!

Set Application.Printer = Application.Printers(Me.TextPrinter)
DoCmd.OpenReport "Days"
Set Application.Printer = Nothing

They both have the same information. But the second one gives an error
message. RunTime Error 5, Illegal Procedjure>

Thanks
DS
 
DS said:
How come one works, This One

Set Application.Printer = Application.Printers(Me.Text0.Column(1))
DoCmd.OpenReport "Days"
Set Application.Printer = Nothing


But this one doesn't!

Set Application.Printer = Application.Printers(Me.TextPrinter)
DoCmd.OpenReport "Days"
Set Application.Printer = Nothing

They both have the same information. But the second one gives an error
message. RunTime Error 5, Illegal Procedjure>

Thanks
DS
Sorry, The first one is an unbound Combo Box and the second is an
unbound Textbox.
Thanks
DS
 
DS said:
Sorry, The first one is an unbound Combo Box and the second is an
unbound Textbox.
Thanks
DS
After Playing Around....This Works, Why I don't know!
Set Application.Printer = Application.Printers((Me.TextPrinter))
 
DS said:
After Playing Around....This Works, Why I don't know!
Set Application.Printer = Application.Printers((Me.TextPrinter))

This should also work:

Set Application.Printer = Application.Printers(Me.TextPrinter.Value)

It seems the Printers collection accepts either a string (the device
name) or a number (the numeric index of the printer in the collection)
as an index. I guess, though, that the interface is defined in such a
way that if you pass it a control reference, it doesn't force the
evaluation of that reference -- it's the control itself, not its value,
that gets passed; and that fails, because a Control object is neither a
string nor a number.

When you put extra parentheses around the control reference, with

Application.Printers((Me.TextPrinter))

you forced the control to be evaluated, and used its *value* to index
the collection, so it worked.
 
Dirk said:
This should also work:

Set Application.Printer = Application.Printers(Me.TextPrinter.Value)

It seems the Printers collection accepts either a string (the device
name) or a number (the numeric index of the printer in the collection)
as an index. I guess, though, that the interface is defined in such a
way that if you pass it a control reference, it doesn't force the
evaluation of that reference -- it's the control itself, not its value,
that gets passed; and that fails, because a Control object is neither a
string nor a number.

When you put extra parentheses around the control reference, with

Application.Printers((Me.TextPrinter))

you forced the control to be evaluated, and used its *value* to index
the collection, so it worked.
Thanks Dirk, Its nice to know why things work when you figure something
out, rather that just making it work!
DS
 
Back
Top