I have used this code only once and it was actually written by someone else. It involves a form/subform arrangement. Records are selected in subform but code is behind main form. Apparently need global module variables.
Code:
Option Compare Database
Option Explicit
Dim intHeight As Integer 'stores value for number of test records selected for deletion
Dim intTop As Integer 'stores value for position of the first selected record in Tests recordset
Private Sub ctrTests_Exit(Cancel As Integer)
'sets module variables starting values for use in deleting selected tests
intHeight = Me.ctrTests.Form.SelHeight
intTop = Me.ctrTests.Form.SelTop
End Sub
Private Sub RemoveTest()
'Cascade deletions out to individual data tables then delete from Tests table
On Error GoTo err_Proc
With Me.ctrTests.Form.RecordsetClone
If .RecordCount < 1 Then
MsgBox "No tests have been saved. Delete action canceled.", , "RemoveTest Error"
ElseIf intHeight < 1 Then
MsgBox "No tests have been selected. Delete action canceled.", , "RemoveTest Error"
Else
...
End Sub