473,513 Members | 2,654 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

properly displaying results of every record in a report (DAO)

Thanks to everybody who has helped me to get this thing finally working
(somewhat). I got the field names to properly display in the
PageHeaderSection, so I won't post the code from that. Now I'm trying to
populate the records (this is based on a cross-tab query "qryTableOfGrades"
in the Detail section but it only displays the data from the last record in
every record. Here's the code. I wonder what I'm doing wrong:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim rs As DAO.RecordSet
Dim db As DAO.Database
Dim qdf As QueryDef
Dim i As Integer
Dim j As Integer
Dim intNumOfFields As Integer
Dim intRecordCount As Integer

Set db = CurrentDb
Set qdf = db.QueryDefs("qryTableOfGrades")

With qdf
.Parameters("[Forms]!frmSelectCourse]![cboSelectCourse") =
[Forms]![frmSelectCourse]![cboSelectCourse]
End With

Set rs = qdf.OpenRecordset()

rs.MoveLast
intRecordCount = rs.RecordCount
rs.MoveFirst

intNumOfFields = rs.Fields.Count

'Populate data labels
'The first three fields contain student names, course number, and course
discription and don't get used here.
For i = 4 To 45 ' make empty labels invisible.
Me.Controls("lblData" & i).Caption = ""
Me.Controls("lblData" & i).Visible = False
Next i

For j = 1 To intRecordCount
For i = 4 To intNumOfFields - 1 'I don't need the first three fields
here.
Me.Controls("lblData" & i).Visible = True 'make useable labels
visible
Me.Controls("lblData" & i).Caption = rs.Fields(i)
Next i
Next j

Set qdf = Nothing
Set rs = Nothing
set db = Nothing
End Sub
Jun 13 '07 #1
6 1761
Why are you looping through j at all?

Also

Me.("lblData" & i).Visible = True
Me("lblData" & i).Caption = rs.Fields(i).name

will do instead of

Me.Controls("lblData" & i).Visible = True
Me.Controls("lblData" & i).Caption = rs.Fields(i)

Hope this helps,

Gary
"Richard Hollenbeck" <ri****************@verizon.netwrote in message
news:2j_bi.4492$4t5.1810@trndny07...
Thanks to everybody who has helped me to get this thing finally working
(somewhat). I got the field names to properly display in the
PageHeaderSection, so I won't post the code from that. Now I'm trying to
populate the records (this is based on a cross-tab query "qryTableOfGrades"
in the Detail section but it only displays the data from the last record in
every record. Here's the code. I wonder what I'm doing wrong:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim rs As DAO.RecordSet
Dim db As DAO.Database
Dim qdf As QueryDef
Dim i As Integer
Dim j As Integer
Dim intNumOfFields As Integer
Dim intRecordCount As Integer

Set db = CurrentDb
Set qdf = db.QueryDefs("qryTableOfGrades")

With qdf
.Parameters("[Forms]!frmSelectCourse]![cboSelectCourse") =
[Forms]![frmSelectCourse]![cboSelectCourse]
End With

Set rs = qdf.OpenRecordset()

rs.MoveLast
intRecordCount = rs.RecordCount
rs.MoveFirst

intNumOfFields = rs.Fields.Count

'Populate data labels
'The first three fields contain student names, course number, and course
discription and don't get used here.
For i = 4 To 45 ' make empty labels invisible.
Me.Controls("lblData" & i).Caption = ""
Me.Controls("lblData" & i).Visible = False
Next i

For j = 1 To intRecordCount
For i = 4 To intNumOfFields - 1 'I don't need the first three fields
here.
Me.Controls("lblData" & i).Visible = True 'make useable labels
visible
Me.Controls("lblData" & i).Caption = rs.Fields(i)
Next i
Next j

Set qdf = Nothing
Set rs = Nothing
set db = Nothing
End Sub

Jun 14 '07 #2
Thank you Gary,

I will try eliminating the 'j' loop and do your other suggestions, then
write back.

Rich

"Gary Floam" <fl***@comcast.netwrote in message
news:oN******************************@comcast.com. ..
Why are you looping through j at all?

Also

Me.("lblData" & i).Visible = True
Me("lblData" & i).Caption = rs.Fields(i).name

will do instead of

Me.Controls("lblData" & i).Visible = True
Me.Controls("lblData" & i).Caption = rs.Fields(i)

Hope this helps,

Gary
"Richard Hollenbeck" <ri****************@verizon.netwrote in message
news:2j_bi.4492$4t5.1810@trndny07...
>Thanks to everybody who has helped me to get this thing finally working
(somewhat). I got the field names to properly display in the
PageHeaderSection, so I won't post the code from that. Now I'm trying to
populate the records (this is based on a cross-tab query
"qryTableOfGrades" in the Detail section but it only displays the data
from the last record in every record. Here's the code. I wonder what
I'm doing wrong:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim rs As DAO.RecordSet
Dim db As DAO.Database
Dim qdf As QueryDef
Dim i As Integer
Dim j As Integer
Dim intNumOfFields As Integer
Dim intRecordCount As Integer

Set db = CurrentDb
Set qdf = db.QueryDefs("qryTableOfGrades")

With qdf
.Parameters("[Forms]!frmSelectCourse]![cboSelectCourse") =
[Forms]![frmSelectCourse]![cboSelectCourse]
End With

Set rs = qdf.OpenRecordset()

rs.MoveLast
intRecordCount = rs.RecordCount
rs.MoveFirst

intNumOfFields = rs.Fields.Count

'Populate data labels
'The first three fields contain student names, course number, and course
discription and don't get used here.
For i = 4 To 45 ' make empty labels invisible.
Me.Controls("lblData" & i).Caption = ""
Me.Controls("lblData" & i).Visible = False
Next i

For j = 1 To intRecordCount
For i = 4 To intNumOfFields - 1 'I don't need the first three
fields here.
Me.Controls("lblData" & i).Visible = True 'make useable labels
visible
Me.Controls("lblData" & i).Caption = rs.Fields(i)
Next i
Next j

Set qdf = Nothing
Set rs = Nothing
set db = Nothing
End Sub


Jun 14 '07 #3
"Gary Floam" <fl***@comcast.netwrote in message
news:oN******************************@comcast.com. ..
Why are you looping through j at all?

Also

Me.("lblData" & i).Visible = True
Me("lblData" & i).Caption = rs.Fields(i).name

will do instead of

Me.Controls("lblData" & i).Visible = True
Me.Controls("lblData" & i).Caption = rs.Fields(i)

Hope this helps,

Gary
"Richard Hollenbeck" <ri****************@verizon.netwrote in message
news:2j_bi.4492$4t5.1810@trndny07...
>Thanks to everybody who has helped me to get this thing finally working
(somewhat). I got the field names to properly display in the
PageHeaderSection, so I won't post the code from that. Now I'm trying to
populate the records (this is based on a cross-tab query
"qryTableOfGrades" in the Detail section but it only displays the data
from the last record in every record. Here's the code. I wonder what
I'm doing wrong:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim rs As DAO.RecordSet
Dim db As DAO.Database
Dim qdf As QueryDef
Dim i As Integer
Dim j As Integer
Dim intNumOfFields As Integer
Dim intRecordCount As Integer

Set db = CurrentDb
Set qdf = db.QueryDefs("qryTableOfGrades")

With qdf
.Parameters("[Forms]!frmSelectCourse]![cboSelectCourse") =
[Forms]![frmSelectCourse]![cboSelectCourse]
End With

Set rs = qdf.OpenRecordset()

rs.MoveLast
intRecordCount = rs.RecordCount
rs.MoveFirst

intNumOfFields = rs.Fields.Count

'Populate data labels
'The first three fields contain student names, course number, and course
discription and don't get used here.
For i = 4 To 45 ' make empty labels invisible.
Me.Controls("lblData" & i).Caption = ""
Me.Controls("lblData" & i).Visible = False
Next i

For j = 1 To intRecordCount
For i = 4 To intNumOfFields - 1 'I don't need the first three
fields here.
Me.Controls("lblData" & i).Visible = True 'make useable labels
visible
Me.Controls("lblData" & i).Caption = rs.Fields(i)
Next i
Next j

Set qdf = Nothing
Set rs = Nothing
set db = Nothing
End Sub
I was looping through j to loop through each record and through i to loop
through every field number 3. I'm still only getting data from the last
record in the recordset for every single record. I tried eliminating the j
loop but it didn't help:

For i = 1 To rs.RecordCount - 1
For j = 4 To rs.Fields.Count - 1
Me("lblData" & j).Visible = True
Me("lblData" & j).Caption = rs.Fields(j)
Next j
Next i
Jun 17 '07 #4
I was looping through j to loop through each record and through i to loop
through every field number 3. I'm still only getting data from the last
record in the recordset for every single record. I tried eliminating the
j loop but it didn't help:
Yes you are looping correctly, but unfortunately not over the recordset. You
need to do a MoveNext, like this:

For i = 1 To rs.RecordCount - 1
For j = 4 To rs.Fields.Count - 1
Me("lblData" & j).Visible = True
Me("lblData" & j).Caption = rs.Fields(j)
Next j
rs.MoveNext
Next i

Also you could replace "For i = 1 To rs.RecordCount - 1" with:

Do Until rs.EOF
....
Loop

HTH

Jun 17 '07 #5
Yes you are looping correctly, but unfortunately not over the recordset.
You need to do a MoveNext, like this:

For i = 1 To rs.RecordCount - 1
For j = 4 To rs.Fields.Count - 1
Me("lblData" & j).Visible = True
Me("lblData" & j).Caption = rs.Fields(j)
Next j
rs.MoveNext
Next i

Also you could replace "For i = 1 To rs.RecordCount - 1" with:

Do Until rs.EOF
...
Loop

HTH
I added your ideas but I also added a message box to see if the correct
values are ever being read. Sure enough, they are correctly cycling through
all the records. But when they get displayed, it is just the last record's
values in every record--even with the rs.MoveNext. I have these labels in
the detail section and I'm in the sub,

"Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer) ."

Here's my new code:

Do Until rs.EOF 'loop through every record
For j = 3 To rs.RecordCount - 1 'loop through every field
Me("lblData" & j + 1).Visible = True 'make labels visible if
there is data
Me("lblData" & j + 1).Caption = Nz(rs.Fields(j), 0)
'populate the label captions with field data
MsgBox rs.Fields(j).Name & ": " & Nz(rs.Fields(j), 0)
Next j
rs.MoveNext
Loop

***** So to summarize, the correct data is actually being read, as is
demonstrated in the MsgBox, but only the last record is printed to every
record.
Jun 18 '07 #6

"Richard Hollenbeck" <ri****************@verizon.netwrote in message
news:gikdi.2766$Sm5.982@trndny04...
>Yes you are looping correctly, but unfortunately not over the recordset.
You need to do a MoveNext, like this:

For i = 1 To rs.RecordCount - 1
For j = 4 To rs.Fields.Count - 1
Me("lblData" & j).Visible = True
Me("lblData" & j).Caption = rs.Fields(j)
Next j
rs.MoveNext
Next i

Also you could replace "For i = 1 To rs.RecordCount - 1" with:

Do Until rs.EOF
...
Loop

HTH

I added your ideas but I also added a message box to see if the correct
values are ever being read. Sure enough, they are correctly cycling
through all the records. But when they get displayed, it is just the last
record's values in every record--even with the rs.MoveNext. I have these
labels in the detail section and I'm in the sub,

"Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer) ."

Here's my new code:
(oops! I got the loop backwards this time. Here it is corrected)

Do Until rs.EOF ' loop through every record (this works but is printing
wrong)
For j = 3 To rs.Fields.Count - 1 'loop through every field
Me("lblData" & j + 1).Visible = True 'make labels visible if
there is data
Me("lblData" & j + 1).Caption = Nz(rs.Fields(j), 0) 'populate
the label captions with field data
Next j
rs.MoveNext
Loop

except there was a MsgBox in there to track the data being read.
***** So to summarize, the correct data is actually being read, as is
demonstrated in the MsgBox, but only the last record is printed to every
record.

Jun 18 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
309
by: Chuck | last post by:
I am trying to retrive one field from the "company info" table that contains several fields but I want the "company name" field. There is only one record in this table. When I entered the code...
15
6810
by: dixie | last post by:
I have a command to open the Access Options dialogue from code: DoCmd.RunCommand acCmdOptions It also opens the Database Window behind it. Is it possible to open the Options without having...
15
1987
by: Richard Hollenbeck | last post by:
For example, one college course has only 24 students in it, but the following code says there are zero As, 20 Bs, 16 Cs, 4 Ds, and 8 Fs. When it prints it then says 0 As, 40 Bs, 32 Cs, 8 Ds, and...
1
2422
by: balachander | last post by:
i every one, i have problem while creating crystal report using vb.net. this is the problem how can i display only one record using crystal report.but i can able to display all the reocord that...
9
3030
by: Kelii | last post by:
I've been trying to get this piece to work for a few hours, but have given up. I hope someone out there can help, I think the issue is relatively straightforward, but being a novice, I'm stumped....
3
1923
by: rghollenbeck | last post by:
Here's my code so far: Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer) Dim db As DAO.Database Dim rs As DAO.RecordSet Dim qdf As QueryDef Set db =...
25
3687
damonreid
by: damonreid | last post by:
Hey, I am trying to take the results of a query to auto-email people reports only relating to themselves. I can take e-mail addresses from a ListBox and pass them to the SendObject command but I...
3
12342
by: Coll | last post by:
I have a report that I run every quarter. When I opened it this quarter, one of the subreports is not displaying. No error message - just nothing displays where the subreport data should be. If you...
1
6536
by: sxwend | last post by:
I am trying to use the following post results (http://www.thescripts.com/forum/thread189759.html) and add another requirement. I need to send the results to just the email addresses that the query...
0
7257
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7157
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7379
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7535
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7521
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5682
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1591
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.