Making label caption = table field description

S

SAC

I have several tables where I have entered the descriptions of each field.

Can I write a routine for a bound form that would place a label whose
caption = the field's description and a texbox whose data source = the
field?

If so, could you tell me a little bit about how to do it?

Thanks
 
A

Allen Browne

This link demonstrates how to loop through the Fields of a TableDef, getting
the Description property of each field that has one:
http://allenbrowne.com/func-06.html

If the table fields have descriptions at the time you create your form,
Access automatically copies the description into the StatusBarText property
of each control, so perhaps you could also read them from there?
 
S

SAC

Thanks. From this I would know how to set the properties for the textboxes,
but how can I take the StatusBarText property for a text box and set the
caption for its corresponding label?

Thanks again.

I really appreciate your help.
 
S

SAC

Thanks.

From this I would know how to set properties for the text boxes and other
data entry control, but how would I set the caption property of a
corresponding label?

Thanks, again.

I really appreciate the help.
 
A

Allen Browne

I'm not clear when you are trying to do this. Perhaps in the Load event of
the form, you would loop through the Controls collection of the form,
looking at the ControlType or testing if it has a StatusBarText, and then
assigning to the Caption of the attached label. The attached lable will be
Controls(0) of the text box.
 
S

SAC

OH! That it will work!

Sorry I don't quite know the syntax. Here's a routine for naming
conventions I attempted to modify but I'm don't know the syntax:

Public Function LabelNaming(objForm As Form) As String
'To use this function, open your form in design mode _
and call this function from the VBA immediate window, _
supplying the form name as input. Like this:

'NamingConventions Forms![FormName]

Dim c As Control
Dim strNConv As String
Dim intCount As Integer

With objForm
For Each c In objForm.Controls
Select Case c.ControlType
Case acTextBox
strNConv = "txt"
Case acComboBox
strNConv = "cbo"
Case acListBox
strNConv = "lst"
Case acCommandButton
strNConv = "cmd"
Case acImage
strNConv = "img"
Case acOptionGroup
strNConv = "opt"
Case 108
strNConv = "ole"
Case acCheckBox
strNConv = "chk"
Case acToggleButton
strNConv = "tgl"
Case 123
strNConv = "tab"
End Select

If Not c.Name Like strNConv & "*" Then

c.Name = strNConv & c.Name


'****************************************
' Is this the correct syntax:
'****************************************


c.Controls(0).Name = c.StatusBarText


intCount = intCount + 1
End If
Next
End With

MsgBox ("Renamed " & intCount & " controls to comply with " & _
"naming conventions and set respective labels to the statusbartext
property.")
End Function
 
A

Allen Browne

It is the Caption of the label you need to set:
c.Controls(0).Caption = c.StatusBarText

Not sure why you are renaming all the controls.
That would need to be in design view, I suspect.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

SAC said:
OH! That it will work!

Sorry I don't quite know the syntax. Here's a routine for naming
conventions I attempted to modify but I'm don't know the syntax:

Public Function LabelNaming(objForm As Form) As String
'To use this function, open your form in design mode _
and call this function from the VBA immediate window, _
supplying the form name as input. Like this:

'NamingConventions Forms![FormName]

Dim c As Control
Dim strNConv As String
Dim intCount As Integer

With objForm
For Each c In objForm.Controls
Select Case c.ControlType
Case acTextBox
strNConv = "txt"
Case acComboBox
strNConv = "cbo"
Case acListBox
strNConv = "lst"
Case acCommandButton
strNConv = "cmd"
Case acImage
strNConv = "img"
Case acOptionGroup
strNConv = "opt"
Case 108
strNConv = "ole"
Case acCheckBox
strNConv = "chk"
Case acToggleButton
strNConv = "tgl"
Case 123
strNConv = "tab"
End Select

If Not c.Name Like strNConv & "*" Then

c.Name = strNConv & c.Name


'****************************************
' Is this the correct syntax:
'****************************************


c.Controls(0).Name = c.StatusBarText


intCount = intCount + 1
End If
Next
End With

MsgBox ("Renamed " & intCount & " controls to comply with " & _
"naming conventions and set respective labels to the statusbartext
property.")
End Function



Allen Browne said:
I'm not clear when you are trying to do this. Perhaps in the Load event
of
the form, you would loop through the Controls collection of the form,
looking at the ControlType or testing if it has a StatusBarText, and then
assigning to the Caption of the attached label. The attached lable will
be
Controls(0) of the text box.
 
S

SAC

I just thought it would be easier to rename the labels captions rather than
manually doing it since the field name are cryptic (come from a mainframe)
and I entered the descriptions in the tableview so I would know what they
are.

Is that senseable?

Also when I out in this syntax I get an error that "Object doesn't support
this property or method."

Thanks.

Allen Browne said:
It is the Caption of the label you need to set:
c.Controls(0).Caption = c.StatusBarText

Not sure why you are renaming all the controls.
That would need to be in design view, I suspect.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

SAC said:
OH! That it will work!

Sorry I don't quite know the syntax. Here's a routine for naming
conventions I attempted to modify but I'm don't know the syntax:

Public Function LabelNaming(objForm As Form) As String
'To use this function, open your form in design mode _
and call this function from the VBA immediate window, _
supplying the form name as input. Like this:

'NamingConventions Forms![FormName]

Dim c As Control
Dim strNConv As String
Dim intCount As Integer

With objForm
For Each c In objForm.Controls
Select Case c.ControlType
Case acTextBox
strNConv = "txt"
Case acComboBox
strNConv = "cbo"
Case acListBox
strNConv = "lst"
Case acCommandButton
strNConv = "cmd"
Case acImage
strNConv = "img"
Case acOptionGroup
strNConv = "opt"
Case 108
strNConv = "ole"
Case acCheckBox
strNConv = "chk"
Case acToggleButton
strNConv = "tgl"
Case 123
strNConv = "tab"
End Select

If Not c.Name Like strNConv & "*" Then

c.Name = strNConv & c.Name


'****************************************
' Is this the correct syntax:
'****************************************


c.Controls(0).Name = c.StatusBarText


intCount = intCount + 1
End If
Next
End With

MsgBox ("Renamed " & intCount & " controls to comply with " & _
"naming conventions and set respective labels to the statusbartext
property.")
End Function



Allen Browne said:
I'm not clear when you are trying to do this. Perhaps in the Load event
of
the form, you would loop through the Controls collection of the form,
looking at the ControlType or testing if it has a StatusBarText, and then
assigning to the Caption of the attached label. The attached lable will
be
Controls(0) of the text box.


Thanks.

From this I would know how to set properties for the text boxes and other
data entry control, but how would I set the caption property of a
corresponding label?

Thanks, again.

I really appreciate the help.


This link demonstrates how to loop through the Fields of a TableDef,
getting
the Description property of each field that has one:
http://allenbrowne.com/func-06.html

If the table fields have descriptions at the time you create your
form,
Access automatically copies the description into the StatusBarText
property
of each control, so perhaps you could also read them from there?

I have several tables where I have entered the descriptions of each
field.

Can I write a routine for a bound form that would place a label
whose
caption = the field's description and a texbox whose data source = the
field?
 
S

SAC

I don't think so. I ran the autoform: columnar wizard to make the form.
All the controls are textboxes and all have labels.
 
S

SAC

Oh, when I attempt to see the c.StatusBarText in a msgbox by:

msgbox(c.StatusBarText )

I get the same error.
 
S

SAC

It must not have been a textbox when I was running it becasue when I put in
an If...then to test for it being a textbox it worked. Maybe it was on the
label when it was bombing out.

Thanks again.
 

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