Why isn't this code changing the labels on a datasheet?
Posted on 2012-09-06
I have created a subform that contains a datasheet. I need to control which columns display and need to assisgn suitable labels on the form so I have created a table with the relevant data and I am using the following code in the ON LOAD event. I have renamed all the Labels as "Label" followed by the variable name. When I step through the code it seems to work but when the form displays the label names have not changed. Can anyone help me figure out what I am doing wrong?
Private Sub Form_Load()
Dim rs As Recordset
Dim sSql As String
Set rs = CurrentDb.OpenRecordset("SELECT tblAbbreviations.* FROM tblAbbreviations ORDER BY Sequence;")
sSql = "SELECT "
Do Until .EOF
Me.Controls("Label" & !FieldName).Caption = Nz(!Abbreviation, !FieldName)
Me.Controls(!FieldName).ColumnHidden = Not !Show
Set rs = Nothing