Setting captions for fields in datasheet view with VBA

  • Thread starter Thread starter Adam
  • Start date Start date
A

Adam

I am trying to create a form with a subform in VBA code, where the subform
is in datasheet view.

I would like to be able to specify captions for the fields in the datasheet
that are not the same as the control names, but I can't figure out a way to
do this. Any suggestions?

Many thanks
 
Adam,

Did you try Me.ControlName.Caption ? You might have to
use Me!ControlName.Caption depending on the Access version.

HTH

Steve
 
on the underliying query, use labels for the fields.

Select fname AS [First Name], lname AS [Last Name] from Employees
 
Thanks for the suggestion, but it doesn't seem to work.

What I have discovered is that if a label is linked to the field, then the
datasheet field will take whatever caption the label has. The trouble is, I
can't figure out how to create a linked label via code.

Any ideas?
 
Unless I'm missing something, text boxes and combo boxes don't have a
caption property. At least, Access 2000 won't let me set them.

Adam
 
Adam,

Create the label you want, then click Cut on the toolbar,
click the control you want to attach the label to and
click Paste on the toolbar.

(See: "Attach a label to a text box or other control in a
form or report" in MSAccess Help)

Glenn
-----Original Message-----
Thanks for the suggestion, but it doesn't seem to work.

What I have discovered is that if a label is linked to the field, then the
datasheet field will take whatever caption the label has. The trouble is, I
can't figure out how to create a linked label via code.

Any ideas?

hal boyles said:
on the underliying query, use labels for the fields.

Select fname AS [First Name], lname AS [Last Name] from Employees


.
 
you have to specify parent argument of createcontrol function

'Create child label control for text box.
Set ctlLabel = CreateControl(frm.Name, acLabel, , ctlText.Name, _
"NewLabel", intLabelX, intLabelY)

--
Alex Dybenko (MVP)
http://Alex.Dybenko.com



Adam said:
Thanks for the suggestion, but it doesn't seem to work.

What I have discovered is that if a label is linked to the field, then the
datasheet field will take whatever caption the label has. The trouble is, I
can't figure out how to create a linked label via code.

Any ideas?

hal boyles said:
on the underliying query, use labels for the fields.

Select fname AS [First Name], lname AS [Last Name] from Employees
 
Thanks, Alex, you're a genius! That works perfectly.

Adam

Alex Dybenko said:
you have to specify parent argument of createcontrol function

'Create child label control for text box.
Set ctlLabel = CreateControl(frm.Name, acLabel, , ctlText.Name, _
"NewLabel", intLabelX, intLabelY)

--
Alex Dybenko (MVP)
http://Alex.Dybenko.com



Adam said:
Thanks for the suggestion, but it doesn't seem to work.

What I have discovered is that if a label is linked to the field, then the
datasheet field will take whatever caption the label has. The trouble
is,
I
can't figure out how to create a linked label via code.

Any ideas?

hal boyles said:
on the underliying query, use labels for the fields.

Select fname AS [First Name], lname AS [Last Name] from Employees
 
You're right. I was thinking while typing and the fingers
and brain got crossed.

What I meant was Me.LabelName.Caption.

If you can't specify the label caption when you create the
control, you might have to brute force it. Step thru all
the labels in the form, compare the label caption to a
list of field names and set the caption to what you want
if the caption is equal to the field name.

Hopefully there is a better way.

Steve
 
Back
Top