Break Code within While Loop

G

Guest

Hi All,

Thanks to this forum I am using the code below to loop through a recordset.
In the first “If†statement within the loop: it assigns values based on the
date. In the second “If†statement: if the date is outside of a certain
range, a message appears and the code should move to after the loop.

I think I need a “Break†statement in there just before the 2nd “End Ifâ€
statement, but I don’t know the syntax and I’m not even sure if “Break†is
actually what I should use. I tried to use a “GoTo StopCode†then put
“StopCode:†before the “End Sub†but that just froze the application.

Dim RsC As DAO.Recordset

Set RsC = Me.RecordsetClone
RsC.MoveFirst
While Not RsC.EOF
Me.Bookmark = RsC.Bookmark

If [DATE] = [Forms]![frm_PVD]![tbl_PVD_subform].Form![PVD_Date] Then

Chk_Add = -1
Me![ID_oss_tran] = [Forms]![frm_PVD]![tbl_PVD_subform].Form![ID]

End If

If [Forms]![frm_PVD]![tbl_PVD_subform].Form![PVD_Date] <
DLookup("[BeginDate]", "dbo_oss_vhb_Data_Input") _
Or [Forms]![frm_PVD]![tbl_PVD_subform].Form![PVD_Date] >
DLookup("[EndDate]", "dbo_oss_vhb_Data_Input") Then

MsgBox "This record is out of the period date range.", vbOKOnly

'********************
'Break; ????
'********************

End If

RsC.MoveNext
Wend
Me.Requery
Set RsC = Nothing

I hope I explained this clear enough, any help will be much appreciated.

Thanks,
Rachel
 
G

Guest

You get out of a loop, such as WHILE, with an EXIT statement. In your case,
EXIT DO will get you out.

BrerGoose
 
M

Marshall Barton

I'm not even going to try to understand what/why you are
doing with that code.

Note that While ... Wend is an archaic contruct.
I think the construct you are asking about is:

Do Until RsC.EOF
. . .
Exit Do
. . .
Loop
 

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