Setting form control propoerties via code

  • Thread starter Thread starter WSF
  • Start date Start date
W

WSF

Access97

I am trying to work out a way to set control.visible properties depending on
User.
I have a table containing the list of controls [ControlName] against which
is listed the form's name [FormName] and each user a separate field - the
field name is their login initials (e.g. [ab] [cd] [ef] etc) The user fields
are Yes/No.

What I would like to do is open the recordset and have a simple function
that extracted the form name and control and set its .visible property to
whatever the user field holds. That is by populating the recordset
(MoveLast, MoveFirst)
With [the recordset]
Flag = .Fields(LoginInitials)

I have tested the extraction of the data with a message box - msgbox
FormName & "!" & ControlName & ".Visible = " & Flag
By looping through MoveNext this "displays" the correct string and goes
through the list of Forms - Controls etc in the list until EOF.
Great.

But how do I get this to work to actually set the property of the control to
whatever the flag is down through the list?

Is there a better way of doing this?

Any help gratefully appreciated

WSF
 
WSF said:
Access97

I am trying to work out a way to set control.visible properties depending on
User.
I have a table containing the list of controls [ControlName] against which
is listed the form's name [FormName] and each user a separate field - the
field name is their login initials (e.g. [ab] [cd] [ef] etc) The user fields
are Yes/No.

What I would like to do is open the recordset and have a simple function
that extracted the form name and control and set its .visible property to
whatever the user field holds. That is by populating the recordset
(MoveLast, MoveFirst)
With [the recordset]
Flag = .Fields(LoginInitials)

I have tested the extraction of the data with a message box - msgbox
FormName & "!" & ControlName & ".Visible = " & Flag
By looping through MoveNext this "displays" the correct string and goes
through the list of Forms - Controls etc in the list until EOF.
Great.

But how do I get this to work to actually set the property of the control to
whatever the flag is down through the list?


Having a separate column for each user in the table is a
poor approach. Proper normalization rules state that you
should have one row per user in a separate table.

Anyway, you are using the wrong syntax to refer to a
control. The correct syntax is:

Me.Controls(ControlName).Visible = Flag
or just
Me(ControlName).Visible = Flag
 
Back
Top