Trying to refer to control, not control's value

P

Phil

Hi all,

I'm about to chew off my arm for this one, because it's
probably pretty simple and I'm just not seeing it or
finding past articles on it...

I want to refer to a control on an open form in order to
requery the control, and I using something very similar
to the example code given in the help. Here is the
example code in MS Access help:

Public Sub RequeryList()

Dim ctlCombo As Control

' Return Control object pointing to a combo box.
Set ctlCombo = Forms!Employees!ReportsTo

' Requery source of data for list box.
ctlCombo.Requery

End Sub

And here is my code:
Dim ctl as Control

Set ctl = Form![frmPatientRecord].Controls
[Me.txtHiddenControl)

ctl.Requery

The only real difference is that I want to refer to a
control that I pass into the current form, so the
Me.txtHiddenControl is a string value that is also the
name of a control on the form frmPatientRecord.

What I keep getting ctl set to is the value of the
control on the open form, not actually the control itself.

What am I not understanding?
 
J

John Vinson

Public Sub RequeryList()

Dim ctlCombo As Control

' Return Control object pointing to a combo box.
Set ctlCombo = Forms!Employees!ReportsTo

' Requery source of data for list box.
ctlCombo.Requery

End Sub

Try instead:

Set ctlCombo = Forms!Employees.Controls("ReportsTo")
 
D

Dave Cousineau

what is Me.txtHiddenControl, is it a textbox?
if it is you want to use txtHiddenControl.Value, or
txtHiddenControl.Text

so your requery statement would be:

Forms!frmPatientRecord.Controls
(Me.txtHiddenControl.Value).Requery
 
M

Marshall Barton

Phil said:
Hi all,

I'm about to chew off my arm for this one, because it's
probably pretty simple and I'm just not seeing it or
finding past articles on it...

I want to refer to a control on an open form in order to
requery the control, [snip]

And here is my code:
Dim ctl as Control

Set ctl = Form![frmPatientRecord].Controls
[Me.txtHiddenControl)

ctl.Requery

The only real difference is that I want to refer to a
control that I pass into the current form, so the
Me.txtHiddenControl is a string value that is also the
name of a control on the form frmPatientRecord.

Use this syntax:

Set ctl =
Forms![frmPatientRecord].Controls(Me.txtHiddenControl)

Note, when posting code to a newsgroup, you should
copy/paste the code you actually have in order to remove
doubts about your typos. E.g. Form!... instead of Forms!..
and the [ balanced by ).
 
G

Guest

Many apologies about the typo, I've been trying a few
things and it begins to get jumbled...

Actually, the code you mention:
Set ctl = Forms![frmPatientRecord].Controls
(Me.txtHiddenControl)

is what I used and still get the value assigned to ctl.

Any other suggestions?
-----Original Message-----
Phil said:
Hi all,

I'm about to chew off my arm for this one, because it's
probably pretty simple and I'm just not seeing it or
finding past articles on it...

I want to refer to a control on an open form in order to
requery the control, [snip]

And here is my code:
Dim ctl as Control

Set ctl = Form![frmPatientRecord].Controls
[Me.txtHiddenControl)

ctl.Requery

The only real difference is that I want to refer to a
control that I pass into the current form, so the
Me.txtHiddenControl is a string value that is also the
name of a control on the form frmPatientRecord.

Use this syntax:

Forms![frmPatientRecord].Controls(Me.txtHiddenControl)

Note, when posting code to a newsgroup, you should
copy/paste the code you actually have in order to remove
doubts about your typos. E.g. Form!... instead of Forms!..
and the [ balanced by ).
 
M

Marshall Barton

Many apologies about the typo, I've been trying a few
things and it begins to get jumbled...

Actually, the code you mention:
Set ctl = Forms![frmPatientRecord].Controls
(Me.txtHiddenControl)

is what I used and still get the value assigned to ctl.


That's surprising since ctl is declared to be a control
object and we're Setting it to a control reference.

How do you know that ctl only has a value?
What happens on the
ctl.Requery
line?
--
Marsh
MVP [MS Access]


-----Original Message-----
Phil said:
I'm about to chew off my arm for this one, because it's
probably pretty simple and I'm just not seeing it or
finding past articles on it...

I want to refer to a control on an open form in order
to requery the control, [snip]

And here is my code:
Dim ctl as Control

Set ctl = Form![frmPatientRecord].Controls
[Me.txtHiddenControl)

ctl.Requery

The only real difference is that I want to refer to a
control that I pass into the current form, so the
Me.txtHiddenControl is a string value that is also the
name of a control on the form frmPatientRecord.
Marshall said:
Use this syntax:

Forms![frmPatientRecord].Controls(Me.txtHiddenControl)

Note, when posting code to a newsgroup, you should
copy/paste the code you actually have in order to remove
doubts about your typos. E.g. Form!... instead of
Forms!.. and the [ balanced by ).
 
T

TC

Jumping in here, there is no way that this:

dim ctl as control
set ctl = ...

will assign a "value" (not a control) to ctl.

What leads you to say that ctl is getting a "value"?

Remember that the Value property is the default property of a control
object.

So if you do this:

msgbox ctl

you will probably see the value of the control that is referenced by the ctl
variable; but ctl still contains a reference - not a "value".

HTH,
TC


Many apologies about the typo, I've been trying a few
things and it begins to get jumbled...

Actually, the code you mention:
Set ctl = Forms![frmPatientRecord].Controls
(Me.txtHiddenControl)

is what I used and still get the value assigned to ctl.

Any other suggestions?
-----Original Message-----
Phil said:
Hi all,

I'm about to chew off my arm for this one, because it's
probably pretty simple and I'm just not seeing it or
finding past articles on it...

I want to refer to a control on an open form in order to
requery the control, [snip]

And here is my code:
Dim ctl as Control

Set ctl = Form![frmPatientRecord].Controls
[Me.txtHiddenControl)

ctl.Requery

The only real difference is that I want to refer to a
control that I pass into the current form, so the
Me.txtHiddenControl is a string value that is also the
name of a control on the form frmPatientRecord.

Use this syntax:

Forms![frmPatientRecord].Controls(Me.txtHiddenControl)

Note, when posting code to a newsgroup, you should
copy/paste the code you actually have in order to remove
doubts about your typos. E.g. Form!... instead of Forms!..
and the [ balanced by ).
 

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