Change a subform control property with code

J

Jay

I have a form with a subform
the subform's SourceObject is changed to a crosstab query on an after
update event
This means that non of the cotrols exist until this point
I know the name of one control and want to set its after update event after
the source object has been updated
I can get code to list all of the control names in the subform but cannot
get it to change the properties of said controls
here is the code and the 3 ways I have already tried
Me.Controls("sbfrmControl").SourceObject =
"Query.qryContracts_HrsPer_Week_Crosstab"
'attempt 1
Me.Controls("sbfrmControl").Controls("WkNo").BackColor = 1
' attempt 2
Forms![frmContractHours]![sbfrmControl].Form.Controls("WkNo").BackColor = 1
'attempt 3
For Each ctl In Forms![frmContractHours]![sbfrmControl].Form.Controls
If ctl.Name = "WKNO" Then
ctl.BackColor = 255
End If
Next ctl


Is this possible??
 
N

NthDegree via AccessMonster.com

Jay,

Your third attempt looks just about right but quite. Try this:
Forms!sbfmcontrol.Controls!twkno.BackColor = 1
I have a form with a subform
the subform's SourceObject is changed to a crosstab query on an after
update event
This means that non of the cotrols exist until this point
I know the name of one control and want to set its after update event after
the source object has been updated
I can get code to list all of the control names in the subform but cannot
get it to change the properties of said controls
here is the code and the 3 ways I have already tried
Me.Controls("sbfrmControl").SourceObject =
"Query.qryContracts_HrsPer_Week_Crosstab"
'attempt 1
Me.Controls("sbfrmControl").Controls("WkNo").BackColor = 1
' attempt 2
Forms![frmContractHours]![sbfrmControl].Form.Controls("WkNo").BackColor = 1
'attempt 3
For Each ctl In Forms![frmContractHours]![sbfrmControl].Form.Controls
If ctl.Name = "WKNO" Then
ctl.BackColor = 255
End If
Next ctl

Is this possible??
 
J

Jay

Hi

I think your code would mean the the subform would have to exist as an
independant object
This subform has as its source object a crosstab query - therefore the
suform cannot be referenced without using the parent form name

Also all of the expressions below gave me the same error message - you
entered an expression that has an invalid reference to the property
backcolor
I have also looped through the properties for the controls and backcolor is
not
listed - are ColumnWidth
ColumnOrder
ColumnHidden
Name
ControlType
ControlSource
Enabled
Locked
Format
Text
SelStart
SelLength
SelText
SmartTags

I am actually trying to set the onclick event for the control - but am using
backcolor to see if the properties are accessible



NthDegree via AccessMonster.com said:
Jay,

Your third attempt looks just about right but quite. Try this:
Forms!sbfmcontrol.Controls!twkno.BackColor = 1
I have a form with a subform
the subform's SourceObject is changed to a crosstab query on an after
update event
This means that non of the cotrols exist until this point
I know the name of one control and want to set its after update event after
the source object has been updated
I can get code to list all of the control names in the subform but cannot
get it to change the properties of said controls
here is the code and the 3 ways I have already tried
Me.Controls("sbfrmControl").SourceObject =
"Query.qryContracts_HrsPer_Week_Crosstab"
'attempt 1
Me.Controls("sbfrmControl").Controls("WkNo").BackColor = 1
' attempt 2
Forms![frmContractHours]![sbfrmControl].Form.Controls("WkNo").BackColor = 1
'attempt 3
For Each ctl In Forms![frmContractHours]![sbfrmControl].Form.Controls
If ctl.Name = "WKNO" Then
ctl.BackColor = 255
End If
Next ctl

Is this possible??
 

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