trying to assign a control on a report a value from a table and am getting an error message desc

trying to assign a control on a report a value from a table and am getting an error message described belowI have a report module in MS Access 2003 and I know I have written code to do this before but I cannot get it to work! Please Help. A copy of the module is displayed below. when I run this code I get the following MS VB error: Run-time error '2448'; You can't assign a value to this object. I haven't programmed in almost 4 years but I know I have done this before. I have a textbox control on the form named MainLanes which I am trying to put data into. Please Help ASAP! Thanks

Option Compare Database

Dim db As Database
Dim rst As Recordset
Dim TotalRecs As Long
Dim i As Long
Dim District As String
Dim REC As Integer
Dim di_int As Integer
Dim stringname As String


Private Sub report_open(Cancel As Integer)

Set db = CurrentDb()
'Set rst = db.OpenRecordset("SELECT System.REC,System.HWY_STAT,System.DI,System.LEN_SEC,System.RDBD_ID FROM System ORDER BY System.REC System.HWY_STAT,System.District,System.RDBD_ID")
Set rst = db.OpenRecordset("System")
TotalRecs = rst.RecordCount
rst.MoveLast
rst.MoveFirst
'Debug.Print TotalRecs
If rst.RecordCount > 0 Then
For i = 1 To TotalRecs
'Debug.Print rst.REC
'Debug.Print "District ID:" & rst!DI
'Debug.Print "HWY_STAT:" & rst!HWY_STAT
'Debug.Print "HWY_SYS:" & rst!HSYS
'Debug.Print "LEN_SEC:" & rst!LEN_SEC
'Debug.Print "RDBD_ID:" & rst!RDBD_ID
'Reports![Fill Report]![Quantity] = rs![QuantityPerUnit]
Me!MainLanes = rst!LEN_SEC
'Me![MainLanes] = rst!LEN_SEC
'Debug.Print Me!MainLanes
stringname = Me!MainLanes.Visible
'Debug.Print stringname
'Debug.Print Me!MainLanes
'Me!MainLanes = "this is the date"

'Debug.Print i
rst.MoveNext
Next i
End If

End Sub

[2047 byte] By [MarshaD.Carpenter] at [2008-1-6]
# 1

Hi Marsha

Not sure if this is your problem but you need to swap the below top two lines around. The Recordcount property is not correct until the last record is reached.

TotalRecs = rst.RecordCount
rst.MoveLast
rst.MoveFirst

should be:


rst.MoveLast

TotalRecs = rst.RecordCount
rst.MoveFirst

ADG at 2007-9-28 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...
# 2

Thank You! I was so happy that someone responded!!! Thank You! I actually stored the record count into the variable TotalRecs & verified via debug that all the records exist and debug.printed some of the fields. My problem is that I cannot set the value of a textbox to a string or a number. I should be able to do this, right? That is, set a textbox value equal to something? I know I have generated reports before where I was able to do this. Maybe I am not in the right event procedure for generating a detail line?

Thank you so much for your response?

MarshaD.Carpenter at 2007-9-28 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...