Changing datasheet column titles on the fly?

G

Guest

I have a form that contains a subform displayed in datasheet view. I want to
be able to change several column headings of the subform depending on values
selected by the user on the main form. The column headings appear to be
coming from the .Name property of each object in the subform. Changing this
when you have code tied to the objects does not seem a good idea. Any tips on
how to do this using other methods?
 
T

tina

in the subform's design view, take a look at the Caption property of the
Label attached to each control. i'm guessing that the name of the control
matches the Caption of the attached label.

if you want a particular label's caption changed immediately after the value
in a mainform control is changed, then add code to the mainform control's
AfterUpdate event, as

Dim strCaption As String

Select Case Me!MainFormControlName
Case "something"
strCaption = "x"
Case "something else
strCaption = "y"
Case Else
strCaption = "z"
End Select

Me!SubformCONTROLName!SubformLabelName.Caption = strCaption

look up Select Case in Access VBA Help, so you'll understand how it works.

hth
 
D

Dirk Goldgar

Bruce said:
I have a form that contains a subform displayed in datasheet view. I
want to be able to change several column headings of the subform
depending on values selected by the user on the main form. The column
headings appear to be coming from the .Name property of each object
in the subform. Changing this when you have code tied to the objects
does not seem a good idea. Any tips on how to do this using other
methods?

If the controls on the form have attached labels, the captions of those
labels override the names of the controls. So you could change the
captions of those labels at run time. The attached label of a control is
a member of that control's Controls collection. So you could write
something similar to this example:

With Me.Subform1.Form
!ID.Controls(0).Caption = "New ID Header"
!Desc.Controls(0).Caption = "New Desc Header"
!Modified.Controls(0).Caption = "New Modified Header"
End With

(where ID, Desc, and Modified are controls on the form).
 

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