end a subroutine in an if statement?

w_drury
04-15-2002, 02:09 PM
Is it possible to end a sub routine while in an if statement.

I am trying to populate a review form with data that meets certain criteria and if the last record has been used in the review I want the sub to end before continuing to the next line of code.

I am using ADO and this is the first part of the code:


Dim result As Integer
Dim varBookmark As Variant

frmCategoryReview.Show

result = InputBox("What Category do you want to review?", "Highway Cost Estimation")

'Put in code for loading review items

frmCategoryReview.Show

frmCategoryReview.lblCategoryChosenToReview.Caption = result


With frmCategorySheetDataEntry.Data1.Recordset

.MoveLast
.MoveFirst

Do Until .EOF


If ![Item Cost] > 0 And !Category = result Then

frmCategoryReview.lblRow1ItemNumber.Caption = ![Item Number]
frmCategoryReview.lblRow1Location.Caption = !Location
frmCategoryReview.lblRow1CategoryCode.Caption = ![Category Code]
frmCategoryReview.lblRow1Quantity.Caption = !Quantity
frmCategoryReview.lblRow1UnitCost.Caption = ![Unit Cost]
frmCategoryReview.lblRow1ItemCost.Caption = ![Item Cost]
.MoveNext
If .EOF = True Then


End

Else



varBookmark = frmCategorySheetDataEntry.Data1.Recordset.Bookmark

End If

Exit Do

Else


End If
.MoveNext
Loop

End With

With frmCategorySheetDataEntry.Data1.Recordset

frmCategorySheetDataEntry.Data1.Recordset.Bookmark = varBookmark

Do Until .EOF

If ![Item Cost] > 0 And !Category = result Then

frmCategoryReview.lblRow2ItemNumber.Caption = ![Item Number]
frmCategoryReview.lblRow2Location.Caption = !Location
frmCategoryReview.lblRow2CategoryCode.Caption = ![Category Code]
frmCategoryReview.lblRow2Quantity.Caption = !Quantity
frmCategoryReview.lblRow2UnitCost.Caption = ![Unit Cost]
frmCategoryReview.lblRow2ItemCost.Caption = ![Item Cost]
.MoveNext
If .EOF = True Then


End
Else


varBookmark = frmCategorySheetDataEntry.Data1.Recordset.Bookmark

End If
Exit Do

Else


End If
.MoveNext
Loop
End With


I know end will not work but hopefully you get the idea of what I want.

Thanks

matticus_99
04-15-2002, 02:13 PM
I normally use Exit Sub.

w_drury
04-15-2002, 02:18 PM
Thanks - why are the easiest things so hard to figure out.

makai
04-16-2002, 12:13 AM
you have a problem that your If is inside a Do - so you really need to Exit the Do first to properly preserve the stack

this may be implemented by setting a boolean before you exit the Do and then have a conditional to check the boolean (and exit Sub) immediately after the Loop

of course if the Sub ends after Loop then no condition would be necessary

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum