R
Razor
Hi,
In my report, I have 11 textboxes named "txt1"
through "txt11" whose ControlSource is being set
dynamically as shown in the code below.
However, I get Run-time error 2191:
"You can't set the controlsource property after printing
has started."
********************************
Private Sub SubProductHeader_Format(Cancel As Integer,
FormatCount As Integer)
Dim db As Database
Dim rs As DAO.Recordset
Dim strSQL As String
Set db = CurrentDb()
strSQL = "SELECT * FROM tblDisplayFields WHERE
SubProductCode = '" & Me.Sub_Product_Code & "' ORDER BY
ListOrder;"
SetLblFalse
SetTxtFalse
Set rs = db.OpenRecordset(strSQL, dbOpenForwardOnly,
dbReadOnly)
Do Until rs.EOF
Dim intCounter As Integer
intCounter = 1
Me("lbl" & intCounter).Visible = True
Me("lbl" & intCounter).Caption = rs!FieldName
With Me("txt" & intCounter)
.Visible = True
.ControlSource = rs!FieldName '<-- offending line
End With
intCounter = intCounter + 1
rs.MoveNext
Loop
rs.Close: Set rs = Nothing
Set db = Nothing
End Sub
Private Sub SetTxtFalse()
Dim intCounter As Integer
For intCounter = 1 To 11
Me("txt" & intCounter).Visible = False
Next intCounter
End Sub
Private Sub SetLblFalse()
Dim intCounter As Integer
For intCounter = 1 To 11
Me("lbl" & intCounter).Visible = False
Next intCounter
End Sub
***********************************
Please advise!
Thanks,
Razor
In my report, I have 11 textboxes named "txt1"
through "txt11" whose ControlSource is being set
dynamically as shown in the code below.
However, I get Run-time error 2191:
"You can't set the controlsource property after printing
has started."
********************************
Private Sub SubProductHeader_Format(Cancel As Integer,
FormatCount As Integer)
Dim db As Database
Dim rs As DAO.Recordset
Dim strSQL As String
Set db = CurrentDb()
strSQL = "SELECT * FROM tblDisplayFields WHERE
SubProductCode = '" & Me.Sub_Product_Code & "' ORDER BY
ListOrder;"
SetLblFalse
SetTxtFalse
Set rs = db.OpenRecordset(strSQL, dbOpenForwardOnly,
dbReadOnly)
Do Until rs.EOF
Dim intCounter As Integer
intCounter = 1
Me("lbl" & intCounter).Visible = True
Me("lbl" & intCounter).Caption = rs!FieldName
With Me("txt" & intCounter)
.Visible = True
.ControlSource = rs!FieldName '<-- offending line
End With
intCounter = intCounter + 1
rs.MoveNext
Loop
rs.Close: Set rs = Nothing
Set db = Nothing
End Sub
Private Sub SetTxtFalse()
Dim intCounter As Integer
For intCounter = 1 To 11
Me("txt" & intCounter).Visible = False
Next intCounter
End Sub
Private Sub SetLblFalse()
Dim intCounter As Integer
For intCounter = 1 To 11
Me("lbl" & intCounter).Visible = False
Next intCounter
End Sub
***********************************
Please advise!
Thanks,
Razor