Report with no data

  • Thread starter Thread starter seeker
  • Start date Start date
S

seeker

I have developed the following code and when I run the report numbers are not
filled in but when I step through the code it does populate the report. What
is the problem?

Private Sub Report_Page()
Dim rs As DAO.Recordset
Dim intcount As Integer
Set rs = CurrentDb.OpenRecordset("qryrandomnumbergenerator")
intcount = 1
While Not rs.EOF
Select Case intcount
Case 1
txtTop1 = rs!TopNumber
txtBottom1 = rs!BottomNumber
Case 2
txtTop2 = rs!TopNumber
txtBottom2 = rs!BottomNumber
Case 3
txtTop3 = rs!TopNumber
txtBottom3 = rs!BottomNumber
Case 4
txtTop4 = rs!TopNumber
txtBottom4 = rs!BottomNumber
Case 5
txtTop5 = rs!TopNumber
txtBottom5 = rs!BottomNumber
Case 6
txtTop6 = rs!TopNumber
txtBottom6 = rs!BottomNumber
Case 7
txtTop7 = rs!TopNumber
txtBottom7 = rs!BottomNumber
Case 8
txtTop8 = rs!TopNumber
txtBottom8 = rs!BottomNumber
Case 9
txtTop9 = rs!TopNumber
txtBottom9 = rs!BottomNumber
Case 10
txtTop10 = rs!TopNumber
txtBottom10 = rs!BottomNumber
Case 11
txtTop11 = rs!TopNumber
txtBottom11 = rs!BottomNumber
Case 12
txtTop12 = rs!TopNumber
txtBottom12 = rs!BottomNumber
Case 13
txtTop13 = rs!TopNumber
txtBottom13 = rs!BottomNumber
Case 14
txtTop14 = rs!TopNumber
txtBottom14 = rs!BottomNumber
Case 15
txtTop15 = rs!TopNumber
txtBottom15 = rs!BottomNumber
Case 16
txtTop16 = rs!TopNumber
txtBottom16 = rs!BottomNumber
Case 17
txtTop17 = rs!TopNumber
txtBottom17 = rs!BottomNumber
Case 18
txtTop18 = rs!TopNumber
txtBottom18 = rs!BottomNumber
Case 19
txtTop19 = rs!TopNumber
txtBottom19 = rs!BottomNumber
Case 20
txtTop20 = rs!TopNumber
txtBottom20 = rs!BottomNumber
Case 21
txtTop21 = rs!TopNumber
txtBottom21 = rs!BottomNumber
Case 22
txtTop22 = rs!TopNumber
txtBottom22 = rs!BottomNumber
Case 23
txtTop23 = rs!TopNumber
txtBottom23 = rs!BottomNumber
Case 24
txtTop24 = rs!TopNumber
txtBottom24 = rs!BottomNumber
Case 25
txtTop25 = rs!TopNumber
txtBottom25 = rs!BottomNumber
Case 26
txtTop26 = rs!TopNumber
txtBottom26 = rs!BottomNumber
Case 27
txtTop27 = rs!TopNumber
txtBottom27 = rs!BottomNumber
Case 28
txtTop28 = rs!TopNumber
txtBottom28 = rs!BottomNumber
Case 29
txtTop29 = rs!TopNumber
txtBottom29 = rs!BottomNumber
Case 30
txtTop30 = rs!TopNumber
txtBottom30 = rs!BottomNumber
Case 31
txtTop31 = rs!TopNumber
txtBottom31 = rs!BottomNumber
Case 32
txtTop32 = rs!TopNumber
txtBottom32 = rs!BottomNumber
Case 33
txtTop33 = rs!TopNumber
txtBottom33 = rs!BottomNumber
Case 34
txtTop34 = rs!TopNumber
txtBottom34 = rs!BottomNumber
Case 35
txtTop35 = rs!TopNumber
txtBottom35 = rs!BottomNumber
Case 36
txtTop36 = rs!TopNumber
txtBottom36 = rs!BottomNumber
End Select
intcount = intcount + 1
rs.MoveNext
Wend
End Sub
 
I suspect the problem is that you are using the Page event
to set the values of text boxes in other sections. Since
the page event occurs after the page has been formatted, the
code should have no effect on the current page. OTOH, the
text boxes on the next page may not be ready to have their
value set.

Whatever you are trying to accomplish, I don't think you can
do it that way.

FYI: You can refer to a (text box) control using the syntax
Me(string)
And that means you could have written your code in a lot
fewer lines:

intcount = 1
Do Until rs.EOF
Me("txtTop" & intcount) = rs!TopNumber
Me("txtBottom" & intcount) = rs!BottomNumber
intcount = intcount + 1
rs.MoveNext
Loop
 
Thank you for the reduced code. I now get an error "you can not assign a
value to this object" at Me("txtTop" & intcount) = rs!TopNumber when it is in
I suspect the problem is that you are using the Page event
to set the values of text boxes in other sections. Since
the page event occurs after the page has been formatted, the
code should have no effect on the current page. OTOH, the
text boxes on the next page may not be ready to have their
value set.

Whatever you are trying to accomplish, I don't think you can
do it that way.

FYI: You can refer to a (text box) control using the syntax
Me(string)
And that means you could have written your code in a lot
fewer lines:

intcount = 1
Do Until rs.EOF
Me("txtTop" & intcount) = rs!TopNumber
Me("txtBottom" & intcount) = rs!BottomNumber
intcount = intcount + 1
rs.MoveNext
Loop
--
Marsh
MVP [MS Access]
I have developed the following code and when I run the report numbers are not
filled in but when I step through the code it does populate the report. What
is the problem?

Private Sub Report_Page()
Dim rs As DAO.Recordset
Dim intcount As Integer
Set rs = CurrentDb.OpenRecordset("qryrandomnumbergenerator")
intcount = 1
While Not rs.EOF
Select Case intcount
Case 1
txtTop1 = rs!TopNumber
txtBottom1 = rs!BottomNumber
Case 2
txtTop2 = rs!TopNumber
txtBottom2 = rs!BottomNumber
Case 3
txtTop3 = rs!TopNumber
txtBottom3 = rs!BottomNumber
Case 4
txtTop4 = rs!TopNumber
txtBottom4 = rs!BottomNumber
Case 5
txtTop5 = rs!TopNumber
txtBottom5 = rs!BottomNumber
Case 6
txtTop6 = rs!TopNumber
txtBottom6 = rs!BottomNumber
Case 7
txtTop7 = rs!TopNumber
txtBottom7 = rs!BottomNumber
Case 8
txtTop8 = rs!TopNumber
txtBottom8 = rs!BottomNumber
Case 9
txtTop9 = rs!TopNumber
txtBottom9 = rs!BottomNumber
Case 10
txtTop10 = rs!TopNumber
txtBottom10 = rs!BottomNumber
Case 11
txtTop11 = rs!TopNumber
txtBottom11 = rs!BottomNumber
Case 12
txtTop12 = rs!TopNumber
txtBottom12 = rs!BottomNumber
Case 13
txtTop13 = rs!TopNumber
txtBottom13 = rs!BottomNumber
Case 14
txtTop14 = rs!TopNumber
txtBottom14 = rs!BottomNumber
Case 15
txtTop15 = rs!TopNumber
txtBottom15 = rs!BottomNumber
Case 16
txtTop16 = rs!TopNumber
txtBottom16 = rs!BottomNumber
Case 17
txtTop17 = rs!TopNumber
txtBottom17 = rs!BottomNumber
Case 18
txtTop18 = rs!TopNumber
txtBottom18 = rs!BottomNumber
Case 19
txtTop19 = rs!TopNumber
txtBottom19 = rs!BottomNumber
Case 20
txtTop20 = rs!TopNumber
txtBottom20 = rs!BottomNumber
Case 21
txtTop21 = rs!TopNumber
txtBottom21 = rs!BottomNumber
Case 22
txtTop22 = rs!TopNumber
txtBottom22 = rs!BottomNumber
Case 23
txtTop23 = rs!TopNumber
txtBottom23 = rs!BottomNumber
Case 24
txtTop24 = rs!TopNumber
txtBottom24 = rs!BottomNumber
Case 25
txtTop25 = rs!TopNumber
txtBottom25 = rs!BottomNumber
Case 26
txtTop26 = rs!TopNumber
txtBottom26 = rs!BottomNumber
Case 27
txtTop27 = rs!TopNumber
txtBottom27 = rs!BottomNumber
Case 28
txtTop28 = rs!TopNumber
txtBottom28 = rs!BottomNumber
Case 29
txtTop29 = rs!TopNumber
txtBottom29 = rs!BottomNumber
Case 30
txtTop30 = rs!TopNumber
txtBottom30 = rs!BottomNumber
Case 31
txtTop31 = rs!TopNumber
txtBottom31 = rs!BottomNumber
Case 32
txtTop32 = rs!TopNumber
txtBottom32 = rs!BottomNumber
Case 33
txtTop33 = rs!TopNumber
txtBottom33 = rs!BottomNumber
Case 34
txtTop34 = rs!TopNumber
txtBottom34 = rs!BottomNumber
Case 35
txtTop35 = rs!TopNumber
txtBottom35 = rs!BottomNumber
Case 36
txtTop36 = rs!TopNumber
txtBottom36 = rs!BottomNumber
End Select
intcount = intcount + 1
rs.MoveNext
Wend
End Sub
 
The Report's Open event is too soon to set the value of any
control. The open event is there to give you a chance to
modify the report's record source query, filtering, sorting,
etc.

The place to set control values is in one or another
section's Format event procedure (almost always the section
containing the controls).

I have no idea what you report looks like nor what objective
the report is supposed to meet so I can't make any concrete
suggestions. Maybe we could make more progress more quickly
if you explained what you are trying to accomplish instead
of going back and forth with issues about how you thought
you could go about it.
--
Marsh
MVP [MS Access]

Thank you for the reduced code. I now get an error "you can not assign a
value to this object" at Me("txtTop" & intcount) = rs!TopNumber when it is in
[snip]
 
Back
Top