loop to delete records doesn't quite work

lscheer

Registered User.
Local time
Today, 19:21
Joined
Jan 20, 2000
Messages
185
I have a loop event attached to a field's after update event. Basically, it is supposed to remove the person from a variety of mailing lists if they are determined inactive. The code actually works, but after deleting the last record, it says the command "delete record" is not available right now...
It seems as if this worked at one time without the error message, but either way, does anyone have any suggestions?

Thanks!

'Remove workshops from invitee list based on "still in field"
Dim strInField As String
Dim blnOmit As Boolean
Dim intCount As Integer

strInField = Forms!frmApplicants!StillInField
blnOmit = Forms!frmApplicants!OmitFromMailings

If strInField = "No" Or blnOmit = True Then
DoCmd.GoToControl "sbfInviteeList"
Do Until intCount > 15
DoCmd.RunCommand acCmdDeleteRecord
Loop
intCount = intCount + 1
End If
 
Since

intCount = intCount + 1

is outside the loop, I'm surprised it doesn't get caught in an endless loop. Are you deleting records from a subform or something? Maybe it runs out of records to delete. Where did the 15 come from?
 
Yes the records are in a subform. The 15 is the an arbitrary number I picked because the person would never have more than 15 records to delete (probably never more than 10, really). And yes, it is running out of records to delete. I assumed that is why I'm getting the message, but I was really wondering if there is anyway NOT to get that message. I'm not an expert coder, so am seeking help here.

Thanks!
 
Simplest, quickest way is to put:

On Error Resume Next

as the first line of the sub.
 
And here I was composing code to get the recordcount of the subform to use for the loop counter. :o
 

Users who are viewing this thread

Back
Top Bottom