473,671 Members | 2,228 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
PageHeaderSecti on, 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 "qryTableOfGrad es"
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(C ancel 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("q ryTableOfGrades ")

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

Set rs = qdf.OpenRecords et()

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("lb lData" & i).Caption = ""
Me.Controls("lb lData" & 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("lb lData" & i).Visible = True 'make useable labels
visible
Me.Controls("lb lData" & 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 1772
Why are you looping through j at all?

Also

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

will do instead of

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

Hope this helps,

Gary
"Richard Hollenbeck" <ri************ ****@verizon.ne twrote in message
news:2j_bi.4492 $4t5.1810@trndn y07...
Thanks to everybody who has helped me to get this thing finally working
(somewhat). I got the field names to properly display in the
PageHeaderSecti on, 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 "qryTableOfGrad es"
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(C ancel 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("q ryTableOfGrades ")

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

Set rs = qdf.OpenRecords et()

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("lb lData" & i).Caption = ""
Me.Controls("lb lData" & 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("lb lData" & i).Visible = True 'make useable labels
visible
Me.Controls("lb lData" & 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).na me

will do instead of

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

Hope this helps,

Gary
"Richard Hollenbeck" <ri************ ****@verizon.ne twrote in message
news:2j_bi.4492 $4t5.1810@trndn y07...
>Thanks to everybody who has helped me to get this thing finally working
(somewhat). I got the field names to properly display in the
PageHeaderSect ion, 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
"qryTableOfGra des" 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(C ancel 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("q ryTableOfGrades ")

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

Set rs = qdf.OpenRecords et()

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("lb lData" & i).Caption = ""
Me.Controls("lb lData" & 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("lb lData" & i).Visible = True 'make useable labels
visible
Me.Controls("lb lData" & 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).na me

will do instead of

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

Hope this helps,

Gary
"Richard Hollenbeck" <ri************ ****@verizon.ne twrote in message
news:2j_bi.4492 $4t5.1810@trndn y07...
>Thanks to everybody who has helped me to get this thing finally working
(somewhat). I got the field names to properly display in the
PageHeaderSect ion, 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
"qryTableOfGra des" 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(C ancel 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("q ryTableOfGrades ")

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

Set rs = qdf.OpenRecords et()

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("lb lData" & i).Caption = ""
Me.Controls("lb lData" & 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("lb lData" & i).Visible = True 'make useable labels
visible
Me.Controls("lb lData" & 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(C ancel 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).Na me & ": " & 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.ne twrote in message
news:gikdi.2766 $Sm5.982@trndny 04...
>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(C ancel 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 below (which I copied out of a book). I get the following error. The hickup comes in the "dim db as database" line. However if I comment this out. It doesn't like the next line either. I appreciate any help you can give me. Also is this a problem...
15
6846
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 the database window open as well? dixie
15
2009
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 16 Fs. The actual number it should show is zero As, 10 Bs, 8 Cs, 2 Ds, and 4 Fs. I can't find anything wrong with the code. Here it is: Option Compare Database Option Explicit 'global variables
1
2432
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 database. can any one help me how to display a particular record. it is possible to get value from the user and display the corresponding record in crystal report.
9
3049
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. Below you will find the code I've written and the error that results. I'm hoping that someone can give me some direction as to what syntax or parameter is missing from the code that is expected by VBA. Overview: I'm trying to copy calculated...
3
1932
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 = CurrentDb Set qdf = db.QueryDefs("qryTableOfGrades")
25
3713
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 want to take a record set (gained from a query) and pass instead. '*****CURRENT CODE***** Private Sub cmdSendRpt2_Click() ' Attach Access Snapshot Report to Email, take addresses from combo box & Send
3
12375
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 run the subreport on its own, it displays fine. It just won't display on the main report. I tried deleting and readding the subreport. No luck. There are other subreports on the main one and they are acting fine. Any ideas? (Using Access 2000)....
1
6552
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 specifies for each record... Essentially this is a make shift Ordering Tool and I want to be able to notify the receiver of the order and its specifics. q_Order_Detail_4email consists of ,,, and Example: Hello@mail.com,956,Modem,1000,xyz123...
0
8473
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8390
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8819
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8597
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8667
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7428
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6222
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5692
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
1806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.