Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange query result.

Status
Not open for further replies.

longmatch

Programmer
Nov 1, 2001
406
I am writing this code try to manipulate data using recordset.

Set db = CurrentDb
strSQL = "SELECT * FROM PtDx WHERE AdmitID=" & [Forms]![admitpt]![AdmitSubform]![Admit ID]
Set rstPtDx = db.OpenRecordset(strSQL)
rstPtDx.MoveFirst
Do Until rstPtDx.EOF
strDx = rstPtDx!Diagnosis & ", " & rstPtDx!ICD9 & " "
rstPtDx.MoveNext
Loop

When I ran the query

"SELECT * FROM PtDx WHERE AdmitID=" & [Forms]![admitpt]![AdmitSubform]![Admit ID]" in access database using query,
it returns correct record number. But when I ran it in module, it only shows 1 record. I don't know why.


Thanks for your help

Haijun
 
Your problem is that you are not populating the recordset.
Change your code to something like:

Set rstPtDx = db.OpenRecordset(strSQL)
If rstPtDx.recordset > 0 then
rstPtDx.Movelast ' populate recordset
rstPtDx.MoveFirst
Else
‘ show message box - no records
end if
Do while not rstPtDx.eof
….
loop


Tom
 
Thank you very much. This problem was solved under your help.

Haijun
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top