Make some fields invisible in a form based on the NAME of the fiel

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is it possible to make some fields invisible in a form based on the "NAME" of the field...
I have more than 40 fields in a single form. For different process,
I will have to display certain fields for data entry.
 
Is it possible to make some fields invisible in a form based on the "NAME" of the field...
I have more than 40 fields in a single form. For different process,
I will have to display certain fields for data entry.

If you name the controls consistently the same text plus a number,
i.e. Text1, Text2, ...Text 40, etc., you can cycle through all the
controls using code. I'll assume you only want to affect text boxes.

Example only showing 2 controls.:

Dim T as TextBox
Dim intCount as integer
for intCount = 1 to 40
Set T = Me("Text" & intCount)
If T.Name = "Text5" or T.Name = "Text28" Then
T.Visible = False
Else
T.Visible = True
End If
Next intCount
===========
For only a few controls, you can name them directly:

[ControlA].Visible = [SomeField] = 3
[ControlB].Vislble = [SomeField] = 5
[ControlC].Visible = Not [SomeField] = 3
etc.
 
Is there a way to select all the field NAME by a SQL statement??

fredg said:
Is it possible to make some fields invisible in a form based on the "NAME" of the field...
I have more than 40 fields in a single form. For different process,
I will have to display certain fields for data entry.

If you name the controls consistently the same text plus a number,
i.e. Text1, Text2, ...Text 40, etc., you can cycle through all the
controls using code. I'll assume you only want to affect text boxes.

Example only showing 2 controls.:

Dim T as TextBox
Dim intCount as integer
for intCount = 1 to 40
Set T = Me("Text" & intCount)
If T.Name = "Text5" or T.Name = "Text28" Then
T.Visible = False
Else
T.Visible = True
End If
Next intCount
===========
For only a few controls, you can name them directly:

[ControlA].Visible = [SomeField] = 3
[ControlB].Vislble = [SomeField] = 5
[ControlC].Visible = Not [SomeField] = 3
etc.
 
I know how to select all the table name by
SELECT DISTINCT MSysObjects.Name FROM MSysObjects WHERE (((MSysObjects.Name) Like "tbl*") AND ((MSysObjects.Type)=1));

but is it possible to select all the field NAME by a SQL statement??

VC said:
Is there a way to select all the field NAME by a SQL statement??

fredg said:
Is it possible to make some fields invisible in a form based on the "NAME" of the field...
I have more than 40 fields in a single form. For different process,
I will have to display certain fields for data entry.

If you name the controls consistently the same text plus a number,
i.e. Text1, Text2, ...Text 40, etc., you can cycle through all the
controls using code. I'll assume you only want to affect text boxes.

Example only showing 2 controls.:

Dim T as TextBox
Dim intCount as integer
for intCount = 1 to 40
Set T = Me("Text" & intCount)
If T.Name = "Text5" or T.Name = "Text28" Then
T.Visible = False
Else
T.Visible = True
End If
Next intCount
===========
For only a few controls, you can name them directly:

[ControlA].Visible = [SomeField] = 3
[ControlB].Vislble = [SomeField] = 5
[ControlC].Visible = Not [SomeField] = 3
etc.
 
I used the following code (obtained from this forum) in a
report to hide fields that are not being used (i.e. that
are blank):

For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
ctl.Visible = Not IsNull(ctl)
End If

Next ctl

I experimented with the same code in a form's Current
event, and it hid the unused text boxes. I expect it
could hide combo boxes, etc. as well. Perhaps you can
adapt it to your needs.
I much prefer to name controls in a way that makes sense
to the database, such as txtFirst and txtLast for name
text boxes, and cboDept for the combo box for selecting
department. I would avoid if possible a naming system
that uses arbitrary control names for the purpose of code
execution.
-----Original Message-----
I know how to select all the table name by
SELECT DISTINCT MSysObjects.Name FROM MSysObjects WHERE
(((MSysObjects.Name) Like "tbl*") AND ((MSysObjects.Type)
=1));
but is it possible to select all the field NAME by a SQL statement??

VC said:
Is there a way to select all the field NAME by a SQL statement??

fredg said:
On Tue, 6 Jul 2004 17:23:01 -0700, VC wrote:

Is it possible to make some fields invisible in a form based on the "NAME" of the field...
I have more than 40 fields in a single form. For different process,
I will have to display certain fields for data entry.

If you name the controls consistently the same text plus a number,
i.e. Text1, Text2, ...Text 40, etc., you can cycle through all the
controls using code. I'll assume you only want to affect text boxes.

Example only showing 2 controls.:

Dim T as TextBox
Dim intCount as integer
for intCount = 1 to 40
Set T = Me("Text" & intCount)
If T.Name = "Text5" or T.Name = "Text28" Then
T.Visible = False
Else
T.Visible = True
End If
Next intCount
===========
For only a few controls, you can name them directly:

[ControlA].Visible = [SomeField] = 3
[ControlB].Vislble = [SomeField] = 5
[ControlC].Visible = Not [SomeField] = 3
etc.
.
 
Back
Top