you are viewing in datasheet? The column heading will take the controlsource of a bound control, or if the control has a bound label, the caption of that label. datasheets do not display unbound controls.The Form shows in datasheet mode.
In design mode it shows 4 labels in the Form Header and 4 Text Boxes in the detail. The Form shows in datasheet mode.
Function ChooseComposer(sArtist, sTitle) As DAO.Recordset
'Union Query to get Composer from CDTracks and mp3Tracks
Dim sql As String
Dim Cap1 As String
Dim rs As DAO.Recordset
Cap1 = "Composer for " & sArtist & Delim & sTitle
sArtist = QuoteIt(CStr(sArtist))
sTitle = QuoteIt(CStr(sTitle))
sql = "SELECT MP3Tracks.TPerformer as Artist, MP3Tracks.TTitle as Title, MP3Tracks.mComposer as Composer, MP3Tracks.Year as Year"
sql = sql & " FROM MP3Tracks Where MP3Tracks.TTitle =" & sTitle
sql = sql & " UNION SELECT CDTracks.TPerformer as Artist , CDTracks.TTitle As Title, CDTracks.TComposer As Composer, CDTracks.[T(P)] As Year"
sql = sql & " FROM CDTRacks Where CDTracks.TTitle =" & sTitle
Set rs = CurrentDb.OpenRecordset(sql)
If rs.RecordCount <> 0 Then
' Form_frmExtSingles.[xLabel Label].Caption = "Composer"
Dim frm As Form
Set frm = Form_frmExtSingles
' Set frm = CurrentProject.AllForms("frmExtSingles")
With frm
!Label.ControlSource = "Composer"
.RecordSource = sql
.TheCaption = Cap1
.Sizer
.Visible = True
End With
Set frm = Nothing
Else
MsgBox "No Matches"
End If
Set rs = Nothing
End Function
If rs.RecordCount <> 0 Then
DoCmd.OpenForm "frmExtSingles", acDesign, , , , acHidden
Forms!frmExtSingles.Form.[xLabel Label].Caption = "Composer"
DoCmd.Close acForm, "frmExtSingles", acSaveYes
DoCmd.OpenForm "frmExtSingles"
Else
MsgBox "No Matches"
End If
Well, that was easy. Check out your database. There is now a button called "new button". It successfully loads the referenced form and changes its label caption to "something", using exactly the method I suggested.I think I have a dumbed version. Open Form1 and click button. Another Form opens and one field is headed "Label"
I want to change this to "Composer" in Function ChooseComposer (if recordCount > 0).
I couldn't put Form_frmExtSingles.Label.Caption = "something" as it errored with Method or data member not found so I remmed it out.
HasModule is Yes.
If somecondition Then
Me.SomeLabel.Caption = "Composer"
Else
Me.Somelabel.Caption = "somethingelse"
End If
Sounds like you deleted the system generated labels that are associated with the controls then added your own labels and expected them to be displayed as the datasheet labels. The associated labels are defined in a control's Control Collection which only has one read only item.Colin and Isaacs changes/suggestions don't do anything if frmExtSingles is Open with view the required acFormDS.
I've since found those 4 label controls aren't actually used and can be removed. Access put them there when teh Form was designed.
controlname.Controls(0)
The field headings in datasheet definitely are normally the associated label captions. I expect the Datasheet label is the ControlName only when there is no associated label.Someone said the field heading or caption takes on the controlsource of a bound control. This suggested the instruction !Label5.ControlSource = "Composer" would also change the column heading to 'Composer'. (I'd first thought it got this from the label controls caption.) Both are wrong. The field heading is the Name of the control.
The associated label is defined in the control's own Controls Collection (different from the Form's Controls Collection). I mentioned this in the previous post.How is a label associated with a control and where in the Form does it go, the detail or somewhere else?
Me.controlname.Controls(0).Caption = "something"
Private Sub Form_Load()
If Left(Me.Caption, 12) = "Composer for" Then
Me.Label13.Caption = "Composer"
Else
Me.Label13.Caption = "Label"
End If
End Sub
Sounds like you deleted the system generated labels
Ah yes I had forgotten about the unattached label dialog (which I assume your video is about.). I turned of that warning in the Access settings a long time ago because I used unattached labels.If Greg is correct you can reconnect a label like this:-