Accessing a control using a db field name...

  • Thread starter Thread starter Brad Pears
  • Start date Start date
B

Brad Pears

I have a table in which are stored control names found on a form.

I want to loop through the records in the table and "enable" the control
names found in the db table...

How can this be done?

Thanks,

Brad
 
dim db as database
dim rs as recordset
set db=currentdb
set rs=db.openrecordset("TableName")
rs.movefirst
do while not rs.eof
me(rs!FieldName).enabled=true
rs.movenet
loop
rs.close
set db=nothing
 
Thanks... One additional question...

If the conmtrols I am setting are on a subform would the syntax to set the
property be something like this...


Forms![frmPricing]![frmMenuItems].Form.RS!ItemControlName.Enabled = True

where frmPricing is the main form and frmMenuItems is the subform and
RS!ItemControlName is the DB fieldname containing the name of the control?

Thanks,

Brad
 
Thanks... Now one additional question...

I am having problems with your syntax and maybe the fact that the controls I
am trying to set are on a subform as opposed to being on the current form...

Here is the syntax I am using...

Forms![frmPricing]![frmMenuItems].Form.RS!ItemControlName.Enabled = True

where "frmPricing" is the main form, "frmMenuItems" is the subform and
RS!ItemControlName is the DB fieldname containing the name of the control.

When I run the code I get an "Application-defined or object-defined error".
In debug, if I substitute the RS!ItemControlName with the actual field
name - it works fine. It appears that it is not obtaining the actual
controls name from RS!ItemControlName and substituting it into the command
syntax properly...

Any ideas on this one?

Thanks,

Brad
 
me.SubFormControlName(rs!FieldName).enabled=true


Brad Pears said:
Thanks... Now one additional question...

I am having problems with your syntax and maybe the fact that the controls I
am trying to set are on a subform as opposed to being on the current form...

Here is the syntax I am using...

Forms![frmPricing]![frmMenuItems].Form.RS!ItemControlName.Enabled = True

where "frmPricing" is the main form, "frmMenuItems" is the subform and
RS!ItemControlName is the DB fieldname containing the name of the control.

When I run the code I get an "Application-defined or object-defined error".
In debug, if I substitute the RS!ItemControlName with the actual field
name - it works fine. It appears that it is not obtaining the actual
controls name from RS!ItemControlName and substituting it into the command
syntax properly...

Any ideas on this one?

Thanks,

Brad

Rob Oldfield said:
dim db as database
dim rs as recordset
set db=currentdb
set rs=db.openrecordset("TableName")
rs.movefirst
do while not rs.eof
me(rs!FieldName).enabled=true
rs.movenet
loop
rs.close
set db=nothing
 
Back
Top