Recordset show previous record when no matching record found

  • Thread starter jayjay21us via AccessMonster.com
  • Start date
J

jayjay21us via AccessMonster.com

I have the following:

Dim dbs As dao.Database
Dim rs As dao.Recordset
Set dbs = Access.application.CurrentDb
Set rs = CurrentDb.OpenRecordset("SELECT DocketID, PLFirst, PLLast, DFFirst,
DFLast FROM HearingSchedule WHERE HearingDate = #" & Forms!Form4!D1 & "#",
dbOpenDynaset)
Do While Not rs.EOF
Forms![Form4].Controls("Mon" & K) = Format(rs!DOCKETID, "####-######") &
Chr(13) & Chr(10) & "PL-" & rs!PLFIRST & rs!PLLAST & Chr(13) & Chr(10) & "DF-
" & rs!DFFIRST & rs!DFLAST
K = K + 1

rs.MoveNext
Loop
rs.Close
Set rs = Nothing
dbs.Close

Set dbs = Nothing

Which works.. But when switch to a date that has no records, the form still
shows the previous record (which had a found date). Do I need to clear the
recordset each time I change dates...

I'm very new at using recordsets.. Any help would be great!!
 
M

Marshall Barton

jayjay21us said:
I have the following:

Dim dbs As dao.Database
Dim rs As dao.Recordset
Set dbs = Access.application.CurrentDb
Set rs = CurrentDb.OpenRecordset("SELECT DocketID, PLFirst, PLLast, DFFirst,
DFLast FROM HearingSchedule WHERE HearingDate = #" & Forms!Form4!D1 & "#",
dbOpenDynaset)
Do While Not rs.EOF
Forms![Form4].Controls("Mon" & K) = Format(rs!DOCKETID, "####-######") &
Chr(13) & Chr(10) & "PL-" & rs!PLFIRST & rs!PLLAST & Chr(13) & Chr(10) & "DF-
" & rs!DFFIRST & rs!DFLAST
K = K + 1

rs.MoveNext
Loop
rs.Close
Set rs = Nothing
dbs.Close

Set dbs = Nothing

Which works.. But when switch to a date that has no records, the form still
shows the previous record (which had a found date). Do I need to clear the
recordset each time I change dates...


That's not a recordset issue. When there are fewer records
in the recordset than the previous time had, the unbound
controls that are not (re)set will still have the values
from the previous time. In other words, you need to clear
the text boxes.
 

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