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

"Set" to a String? 1

Status
Not open for further replies.

sucoyant

IS-IT--Management
Sep 21, 2002
213
US
Good day all!

I'm trying to "Set" to a string... which probably isn't possible. Even so, how would I go about making the following code work?

The comment shows where I get an error of: Run time error '91': Object Variable of With block not set.



Code:
Public Sub EmpRepSelect(shtGrpName As String, ReportName As String)
Dim PRfrom As TextBox
Dim Text1 as String

Text1 = "Me.txt" & shtGrpName & "_PRfrom"

PRfrom = Text1 '<-- Error

...
...
...

End Sub



Any ideas?


________________________________________
BUDDHA.gif
Buddha. Dharma. Sangha.
 
Hi sucoyant,

All you have done with ..

[purple][tt]Dim PRfrom as TextBox[/tt][/purple]

.. is declare your intent to use the variable [purple]PRfrom[/purple] as a pointer to a Textbox; before you can use it you must assign it to an actual textbox object. This is complete guesswork, but perhaps you want ..

[blue]
Code:
Set PRfrom = Me.Controls("txt" & shtGrpName & "_PRfrom")
[/blue]

To help much more really needs a bit more information about what you're trying to achieve.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Works like a charm Tony! Thanks!!

________________________________________
BUDDHA.gif
Buddha. Dharma. Sangha.
 
Hrm.

I saved my Sub as a Module in MS Access, but now when I run it, I get "Invalid use of Me Keyword"

Why would it do this?

________________________________________
BUDDHA.gif
Buddha. Dharma. Sangha.
 
Hi sucoyant,

Me refers to the current instance of a Form or Report from within the Form's (or Report's) Class Module. If you want to reference an (open) Form from somewhere else such as a Module, you must be more explicit. You can use [blue][Forms]![FormName][/blue] or, perhaps, pass a reference to the routine - if it is being called from a Form, then add an extra parameter ..

Code:
[blue]Public Sub EmpRepSelect(shtGrpName As String, ReportName As String[highlight], myForm AS Form[/highlight])
:
:
Set PRfrom = [highlight]myForm[/highlight].Controls("txt" & shtGrpName & "_PRfrom")
[/blue]

and then call it using ..

Code:
[blue]EmpRepSelect([i]GrpName[/i], [i]RptName[/i][highlight], Me[/highlight])
[/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Ahh, perfect!

Thank you SO much Tony! I really do appreciate your expertise.

________________________________________
BUDDHA.gif
Buddha. Dharma. Sangha.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top