Grouping fields

J

Jacco

Hi everyone,

Is there a way to group a set of fields in a form? I mean, I know I can
create a group but I can't name it, so I can't assign any values to it. On
some conditions I want some fields to hide or becomed bold text, and I
wonder if I can group the fields, just to shorten the code. Right now it
goes like this:

[FlightDate_Label].FontWeight = 300
[Aircraft_Label].FontWeight = 300
[RouteFrom_Label].FontWeight = 300
[RouteTo_Label].FontWeight = 300
[OUTTime_Label].FontWeight = 300
[INTime_Label].FontWeight = 300
[AircraftIdent_Label].FontWeight = 300


Thanx,
Jacco
 
M

Mark

With a little thought, you could come up with a naming convention for the
controls you wish to group like this. Then you can write a little For
Each...Next loop to batch process them:

Dim ctl As Control
For Each ctl In Forms!Form1.Controls
If Right(ctl.Name, 5) = "Label" Then
ctl.FontWeight=300
End If
Next ctl
 
J

John Vinson

Hi everyone,

Is there a way to group a set of fields in a form? I mean, I know I can
create a group but I can't name it, so I can't assign any values to it. On
some conditions I want some fields to hide or becomed bold text, and I
wonder if I can group the fields, just to shorten the code. Right now it
goes like this:

[FlightDate_Label].FontWeight = 300
[Aircraft_Label].FontWeight = 300
[RouteFrom_Label].FontWeight = 300
[RouteTo_Label].FontWeight = 300
[OUTTime_Label].FontWeight = 300
[INTime_Label].FontWeight = 300
[AircraftIdent_Label].FontWeight = 300

Mark's naming convention is certainly one good approach; another is to
use the Tag property of the control to label each control in a way
that lets your code identify it. Frex, you could set the Tag of each
of these controls to "FixWeight"; then your code could be

Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "FixWeight" Then
ctl.FontWeight = 300
End If
Next ctl


John W. Vinson[MVP]
 
M

Mark

Hmmmm,
I guess I should start looking at all those control properties! Didn't even
think about the Tag property. Sounds much cleaner than naming the control a
certain way. :)


John Vinson said:
Hi everyone,

Is there a way to group a set of fields in a form? I mean, I know I can
create a group but I can't name it, so I can't assign any values to it. On
some conditions I want some fields to hide or becomed bold text, and I
wonder if I can group the fields, just to shorten the code. Right now it
goes like this:

[FlightDate_Label].FontWeight = 300
[Aircraft_Label].FontWeight = 300
[RouteFrom_Label].FontWeight = 300
[RouteTo_Label].FontWeight = 300
[OUTTime_Label].FontWeight = 300
[INTime_Label].FontWeight = 300
[AircraftIdent_Label].FontWeight = 300

Mark's naming convention is certainly one good approach; another is to
use the Tag property of the control to label each control in a way
that lets your code identify it. Frex, you could set the Tag of each
of these controls to "FixWeight"; then your code could be

Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "FixWeight" Then
ctl.FontWeight = 300
End If
Next ctl


John W. Vinson[MVP]
 
J

Jacco

John Vinson said:
Hi everyone,

Is there a way to group a set of fields in a form? I mean, I know I can
create a group but I can't name it, so I can't assign any values to it. On
some conditions I want some fields to hide or becomed bold text, and I
wonder if I can group the fields, just to shorten the code. Right now it
goes like this:

[FlightDate_Label].FontWeight = 300
[Aircraft_Label].FontWeight = 300
[RouteFrom_Label].FontWeight = 300
[RouteTo_Label].FontWeight = 300
[OUTTime_Label].FontWeight = 300
[INTime_Label].FontWeight = 300
[AircraftIdent_Label].FontWeight = 300

Mark's naming convention is certainly one good approach; another is to
use the Tag property of the control to label each control in a way
that lets your code identify it. Frex, you could set the Tag of each
of these controls to "FixWeight"; then your code could be

Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "FixWeight" Then
ctl.FontWeight = 300
End If
Next ctl


John W. Vinson[MVP]

Hi, both methods work great, and they work as advertised resetting my
fontweight. Now I bumbed into a slight variation that doesn't seem to work:

If the field value is Null, I want the Label to become FontWeight 600:


Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "required_flight" Then
If Nz(ctl.Value, 0) = 0 Then
ctl_label = "[" + ctl.Name + "_Label]" ''''I thought this
would do the trick picking the Label box but it doesn't
ctl_label.FontWeight = 600
End If
End If
Next ctl

Thank you
 
M

Mark

It looks like your labels have the same base name as your text boxes plus
"_Label" right? So the textbox called FlightDate has a label called
FlightDate_Label?

You're on the right track, but the reference to the label should be
something like:

Dim ctl As Control
Dim lbl As String
For Each ctl In Me.Controls
If ctl.Tag = "required_flight" Then
If Nz(ctl.Value, 0) = 0 Then
lbl = ctl.Name & "_Label"
Me.Controls(lbl).FontWeight = 600
End If
End If
Next ctl


Jacco said:
John Vinson said:
Hi everyone,

Is there a way to group a set of fields in a form? I mean, I know I can
create a group but I can't name it, so I can't assign any values to it.
On
some conditions I want some fields to hide or becomed bold text, and I
wonder if I can group the fields, just to shorten the code. Right now it
goes like this:

[FlightDate_Label].FontWeight = 300
[Aircraft_Label].FontWeight = 300
[RouteFrom_Label].FontWeight = 300
[RouteTo_Label].FontWeight = 300
[OUTTime_Label].FontWeight = 300
[INTime_Label].FontWeight = 300
[AircraftIdent_Label].FontWeight = 300

Mark's naming convention is certainly one good approach; another is to
use the Tag property of the control to label each control in a way
that lets your code identify it. Frex, you could set the Tag of each
of these controls to "FixWeight"; then your code could be

Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "FixWeight" Then
ctl.FontWeight = 300
End If
Next ctl


John W. Vinson[MVP]

Hi, both methods work great, and they work as advertised resetting my
fontweight. Now I bumbed into a slight variation that doesn't seem to
work:

If the field value is Null, I want the Label to become FontWeight 600:


Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "required_flight" Then
If Nz(ctl.Value, 0) = 0 Then
ctl_label = "[" + ctl.Name + "_Label]" ''''I thought this
would do the trick picking the Label box but it doesn't
ctl_label.FontWeight = 600
End If
End If
Next ctl

Thank you
 
J

Jacco

Thank you, that did the trick. I had already experimented with Dim as Label,
but still didn't work. As string it works great


Mark said:
It looks like your labels have the same base name as your text boxes plus
"_Label" right? So the textbox called FlightDate has a label called
FlightDate_Label?

You're on the right track, but the reference to the label should be
something like:

Dim ctl As Control
Dim lbl As String
For Each ctl In Me.Controls
If ctl.Tag = "required_flight" Then
If Nz(ctl.Value, 0) = 0 Then
lbl = ctl.Name & "_Label"
Me.Controls(lbl).FontWeight = 600
End If
End If
Next ctl


Jacco said:
John Vinson said:
Hi everyone,

Is there a way to group a set of fields in a form? I mean, I know I can
create a group but I can't name it, so I can't assign any values to it.
On
some conditions I want some fields to hide or becomed bold text, and I
wonder if I can group the fields, just to shorten the code. Right now it
goes like this:

[FlightDate_Label].FontWeight = 300
[Aircraft_Label].FontWeight = 300
[RouteFrom_Label].FontWeight = 300
[RouteTo_Label].FontWeight = 300
[OUTTime_Label].FontWeight = 300
[INTime_Label].FontWeight = 300
[AircraftIdent_Label].FontWeight = 300

Mark's naming convention is certainly one good approach; another is to
use the Tag property of the control to label each control in a way
that lets your code identify it. Frex, you could set the Tag of each
of these controls to "FixWeight"; then your code could be

Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "FixWeight" Then
ctl.FontWeight = 300
End If
Next ctl


John W. Vinson[MVP]

Hi, both methods work great, and they work as advertised resetting my
fontweight. Now I bumbed into a slight variation that doesn't seem to
work:

If the field value is Null, I want the Label to become FontWeight 600:


Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "required_flight" Then
If Nz(ctl.Value, 0) = 0 Then
ctl_label = "[" + ctl.Name + "_Label]" ''''I thought this
would do the trick picking the Label box but it doesn't
ctl_label.FontWeight = 600
End If
End If
Next ctl

Thank you
 
Top