Getting data into unbound text boxes

fearless

New member
Local time
Tomorrow, 03:07
Joined
May 2, 2005
Messages
8
I have a report with the following unbound text boxes in the detail section.
TextNm and Text0-Text5.

I am trying to assign values to each using the following code. However each assignment statements (Me!TextNm = rst.Fields(i).Value) produces the following error "You can't assign a value to this object"

Any help would be appreciated.

Thanks

Private Sub Report_Open(Cancel As Integer)
Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim i As Integer
Dim j As Integer
Set db = CurrentDb
Set rst = db.OpenRecordset("select * from qxtbContribByYear")
rst.MoveFirst
j = -1
i = 0
For i = 0 To rst.Fields.Count - 1
If rst.Fields(i).name Like "*nm" Then
Me!TextNm = rst.Fields(i).Value
GoTo skip_it
End If
j = j + 1
Select Case j
Case 0
Me.Text0 = rst.Fields(i).Value
Case 1
Me.Text1 = rst.Fields(i).Value
Case 2
Me.Text2 = rst.Fields(i).Value
Case 3
Me.Text3 = rst.Fields(i).Value
Case 4
Me.Text4 = rst.Fields(i).Value
Case 5
Me.Text5 = rst.Fields(i).Value
End Select
skip_it:
Next
rst.Clone
Set rst = Nothing

End Sub
 
You need to put the code in the Format section where the fields are.
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim i As Integer
Dim j As Integer
Set db = CurrentDb
Set rst = db.OpenRecordset("select * from qxtbContribByYear")
rst.MoveFirst
j = -1
For i = 0 To rst.Fields.Count - 1
    If rst.Fields(i).Name Like "*nm" Then
        Me!TextNm = rst.Fields(i).Value
    Else
    j = j + 1
        Me("Text" & j) = rst.Fields(i).Value
    End If
Next
rst.Clone
Set rst = Nothing

End Sub

HTH

Peter

(not sure what the rst.Clone is doing in there though!)
 
Last edited:
Peter

Thanks very much. Works like a charm.

Fearless
 

Users who are viewing this thread

Back
Top Bottom