IsObject - varible

Powers143
08-31-2003, 05:06 PM
Here is my code:

Private Sub Try()
Dim jj As Object
Set jj = "Text9"
If IsObject(jj) = True Then
Text3.Text = "exist"
Else
Text3.Text = "blah"
End If
End Sub

I cannot pass the varible in the sub ex: try (jj as object) - due to other reasons that you don't care about.

the code works if jj does exist is not it blows up.

If this in unclear here the actual problem i'm facing.

i have 2 types of dynamic controls on 'formtest' then when the user clicks the flexgrid it determins what type of control is needed.

(a lookup field (employee_name) will use a dynamic combobox (so the user can select a different name) whie the other type (dynamic textbox) would be for money or date columns.)

so what i do is: when i create the controls i give the name of the dyncombobox followed by 'I' where I is the columns number.

then if control dyncomboboxI exists i shall use it for that cell, else use the text box.

Thanks -Doug

Powers143
08-31-2003, 05:12 PM
i have a text1.tag = form1.command1

what i want to bo able to do but don't know how is:

text1.tag.caption = "Starwars"

----
I may have to add a new object or sometihng or maybe parse text, need help.

Thanks
- Doug

Thinker
08-31-2003, 05:15 PM
This code can't ever work. You can't refer to a control by its name in
a string variable/constant/literal.
You can use the Controls collection to get a reference if it exists but if
it doesn't you will get a run-time error. The best method would probably
be to loop through all the controls comparing the name.

Dim tmpCtrl As Control, theCtrl As Control
For Each tmpCtrl in Controls
If tmpCtrl.Name = NameOfSoughtControl Then
Set theCtrl = tmpCtrl
Exit For
End If
Next
...
If theCtrl Is Nothing Then
'Control wasn't found
Else
'Control was found and a reference is in theCtrl
End If

lebb
08-31-2003, 05:19 PM
Textboxes have tag properties and they have caption properties. Either of these can be set to a string, but there's no such thing as text1.tag.caption. What is it that you're trying to accomplish?

Thinker
08-31-2003, 05:20 PM
I merged your two questions because it is really the same type of
question. You are still trying to use string variables with object names
to reference objects directly. It can't be done that way. You have to
somehow use the string to look up the object then acquire a reference
to the object.

Powers143
08-31-2003, 06:30 PM
Yeah i agree both questions are similer - althougt slightly different at any case:

dealing with this case:

i have a text1.tag = form1.command1

what i want to bo able to do but don't know how is:

text1.tag.caption = "Starwars"

- how would i go about referenceing the object?

how it is used: a module creates dynamic contols on a specific form (may be more than one) when the control is created it's called txt_fName . then the user clicks on a cell (ina flexgrid) and use _lostfocus for the control then send the new 'text' back to the cell. Right now i am hard coding the form and grid which i defeats the whole point of a module. so i though i could attach it's 'sender' informatioin into the .tag property of the dynamic control then use that as a reference.
This is obvioulsy where i'm running into problems.
How would i acquire a reference? what else do i do?
I thought of:

Private Sub txtDyn_lostfocus(fName as form, Anyfg as msflexgrid)
If txtDyn Is Nothing Then Exit Sub
'calls a sub to transfer data etc
End Sub

but could't get it right. I saw operations with a 'owner' , 'seneder' but don't know how to use these functions.

Thanks - Doug

Thinker
08-31-2003, 06:34 PM
As I already said, you can't do that. Let me repeat again, you can't do
that. The only way you can work with an object is if you get a
reference to it. The controls collection is your only hope for references
to controls. Look at my sample code above.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum