loop through recordset

T

Tony Piperato

Greetings,

I am opening a recordset and would like to print the results in a report
detail section. I have the following code:

Do Until rsMyRS.EOF
txtDateStart = rsMyRS("DateStart")
txtDateStop = rsMyRS("DateStop")
Debug.Print rsMyRS("DateStart") & " " & rsMyRS("DateStop")
rsMyRS.MoveNext
Loop

txtDateStart and Stop are text boxes in the report detail section. There
are nine records in the RS, but I only get the first records' values printed
nine times instead of EACH individual record. Any thoughts?

Thanks in advance for your help.

Tony
 
D

Doug

I've been working on the same issue for several days
except I'm sending the output to the printer rather than
DeBug. Try:

Debug Print txtDateStart; space(); txtDateStop

Use your variables and notice the semicolons rather than
ampersands. In addition to space (), check out tab().
You can put integers between the ()'s. In the case of tab
(), the integer refers to a specific column rather than
number of spaces. " " probably works too. Let me know
how you do.
 
D

Doug

Also, my code is in the Page event of the main report,
itself. I get to the records by declaring & setting the
database and opening the recordset. The reason you're
getting the same record may be that the "next" record
won't work as you have it. If you need the exact code let
me know. It's not available to me now because I'm at a
friend's house. I wanted to write tonight, before they
remove your original post, and I want to paste it here so
there are no errors. Just figured it out!
 
M

Marshall Barton

Tony said:
Greetings,

I am opening a recordset and would like to print the results in a report
detail section. I have the following code:

Do Until rsMyRS.EOF
txtDateStart = rsMyRS("DateStart")
txtDateStop = rsMyRS("DateStop")
Debug.Print rsMyRS("DateStart") & " " & rsMyRS("DateStop")
rsMyRS.MoveNext
Loop

txtDateStart and Stop are text boxes in the report detail section. There
are nine records in the RS, but I only get the first records' values printed
nine times instead of EACH individual record.


You only have a single txtDateStart text box in the detail
section so it can only display a single value. You didn't
explain enough about your report for me to tell what might
be best for your situation, but here's a couple of ideas you
might try.

Place 9 txtDateStart and txtDateStop text boxes in the
detail section. Name them txtDateStart1 through
txtDateStart9, etc, then use code along these lines:

intK = 0
With rsMyRS
Do Until .EOF
intK = intK + 1
Me("txtDateStart" & intK) = !DateStart
Me("txtDateStop" & intK)= !DateStop
Debug.Print !DateStart & " " &!DateStop
rsMyRS.MoveNext
Loop

Actually, I think this whole approach is probably the wrong
way around and you should use a subreport instead.
 
T

Tony Piperato

Marshall,

Actually I could have an infinite number of records, so your approach won't
work for me. I really just need to know how, after opening a recordset I
can write the contents to the detail area of a report.

Tony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top