Private Sub Report_Open(Cancel As Integer) Dim rst As DAO.Recordset Dim intFields As Integer Dim intControls As Integer Dim N As Integer ' Open a recordset for the crosstab query. Set rst = CurrentDb.OpenRecordset(Me.RecordSource) ' Find the number of text boxes available in the Detail ' section, minus 2 because we don't count the row header ' control (City) or the line control. intControls = Me.Detail.Controls.Count - 1 ' Find the number of fields, minus 1, because we don't ' count the row header field (City) intFields = rst.Fields.Count - 1 ' We can't use more than intControls number of fields If intFields > intControls Then intFields = intControls End If ' Iterate through report fields to set label captions ' and field control sources. For N = 1 To intControls If N <= intFields Then Me.Controls("Label" & N).Caption = rst.Fields(N).Name Me.Controls("Field" & N).ControlSource = rst.Fields(N).Name Else ' Hide extra controls. Me.Controls("Label" & N).Visible = False Me.Controls("Field" & N).Visible = False End If Next N rst.Close End Sub