Setting captions for fields in datasheet view with VBA

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
 
H

hal boyles

on the underliying query, use labels for the fields.

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

Adam

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?
 
A

Alex Dybenko

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
 
A

Adam

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
 

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