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

Store control name in a table 1

Status
Not open for further replies.

Darrylles

Programmer
Feb 7, 2002
1,758
GB
Hi all,

I need to refer to form controls (list boxes) dependent upon selection from a combo.

E.g. if a particular option (data criteria for a form) is selected from a combo - it makes the selected control (list box) visible, ready for the user to select items (criteria options) from that control.

In order to do this, I need to pass a control name parameter to a function as data type Control ('ListBox').

e.g.

Public Sub ShowListbox(lst as Listbox)
...
lst.Visible = TRUE
...
End Sub

I can call the above with a literal control name:

Call ShowListBox (lstNation)

and it works.

I want to store 'lstNation' in a table, but can only store it as a string - which is not recognised as a control when I pass it as a parameter.

Is my only option to enumerate the form's objects? If so, how do I compare the stored string in the table to the list of form objects - in order to select them to make them visible?

Any help much appreciated.

ATB

Darrylle








Can I store a control name in a table, retrieve it and refer to it as a data-type of 'control'?








Never argue with an idiot, he'll bring you down to his level - then beat you with experience.
 
All,

Just did a bit more digging - would this perhaps do it:
thread707-1527983 ?

with control
.name = "control name"
end with

I've no idea yet, but will try this.

Don't let it stop you from suggesting others though!

ATB

Darrylle

Never argue with an idiot, he'll bring you down to his level - then beat you with experience.
 
Sorry All,

But, is this part of the solution:

Me.Controls("my_control_name").Value ?

It seems right, just can't get it to work (Error 424).

ATB

Darrylle

Never argue with an idiot, he'll bring you down to his level - then beat you with experience.
 
Not sure what your problem is exactly.

Just pass the string.

public sub someprocedure (cntrlName as string)
'Assuming you are doing this from
'the form that has the control
'
dim cntrl as access.control
set cntrl = me.controls(cntrlName)
'if calling from a standard module not on the form
' set cntrl = forms("someformName").controls(cntrlName)
cntrl.visible = true
end sub
 
MajP

Sorry for the delay with the star - I couldn't get my head around your solution - with my original issue, but it has helped me since.

Thanks for this.

ATB

Darrylle



Never argue with an idiot, he'll bring you down to his level - then beat you with experience.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top