Wta is the code structure to put Rst.FindNext in a loop? I'm using what I show
below. It works fine but my instinct says it should be in some standard loop
rather than using the GoTo structure.
RstTicket.FindFirst "[TicketID] = " & Me!TicketID
If RstTicket.NoMatch = False Then
<<Some Code>>
CheckForAnotherTicket:
RstTicket.FindNext "[TicketID] = " & Me!TicketID
If RstTicket.NoMatch = False Then
<<Some Code>>
GoTo CheckForAnotherTicket
End If
End If
show
below. It works fine but my instinct says it should be in some standard loop
rather than using the GoTo structure.
RstTicket.FindFirst "[TicketID] = " & Me!TicketID
If RstTicket.NoMatch = False Then
<<Some Code>>
CheckForAnotherTicket:
RstTicket.FindNext "[TicketID] = " & Me!TicketID
If RstTicket.NoMatch = False Then
<<Some Code>>
GoTo CheckForAnotherTicket
End If
End If
No, you don't need the loop. FindFirst actually means find the FIRST
instance / row that matches your criteria but it will search the WHOLE
Recordset if there is no match. Thus, if the FindFirst doesn't find the
matched Record / Row, your FindNext will NEVER find it either!
I disagree. He clearly wants to find a matching record (if any) with
FindFirst, then find subsequent matching records (if any) with FindNext. My
suggestion does that for him. The code that he used before, was wrong. He
*says* that it worked, but my bet is that it didn't.
Perhaps he could step in & clarify (if he's still reading this)?
TC
Van T. Dinh said:
Not quite ... (Please see my reply)
--
HTH
Van T. Dinh
MVP (Access)
TC said:
Your instinct serves you well!
rs.findfirst ....
while not rs.nomatch
.....
rs.findnext ...
wend
RstTicket.FindFirst "[TicketID] = " & Me!TicketID
If RstTicket.NoMatch = False Then
<<Some Code>>
CheckForAnotherTicket:
RstTicket.FindNext "[TicketID] = " & Me!TicketID
If RstTicket.NoMatch = False Then
<<Some Code>>
GoTo CheckForAnotherTicket
End If
End If
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.