Hi, I am trying to set a control source for a field on an Access 2010 report by using the field number. I don't know what the field name will be. I can return the field name on the report but get an error trying to set a fields control source to that field. The error I get is "You can't set the Control Source property in print preview or after printing has started". I put this code in the Detail Onformat event. Any ideas. Lisa
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim r Set r = CurrentDb().OpenRecordset("tblTemp")
FieldCount = r.Fields.Count
If FieldCount > 30 Then
Me.txt1 = r.Fields(30).Name
Me.txtValue1 = r.Fields(30).Value
End If
If FieldCount > 31 Then
Me.txt2 = r.Fields(31).Name
Me.txtValue2.ControlSource = r.Fields(31).Value
End If
End Sub
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim r Set r = CurrentDb().OpenRecordset("tblTemp")
FieldCount = r.Fields.Count
If FieldCount > 30 Then
Me.txt1 = r.Fields(30).Name
Me.txtValue1 = r.Fields(30).Value
End If
If FieldCount > 31 Then
Me.txt2 = r.Fields(31).Name
Me.txtValue2.ControlSource = r.Fields(31).Value
End If
End Sub