' http://www.office-archive.com/3-ms-access/13b3380dd2222309.htm
Private Sub Form_Click()
On Error GoTo FormClickerr
'MsgBox "SelHeight: " & Me.SelHeight & vbTab & "SelTop: " & Me.SelTop
'MsgBox Me.CurrentRecord
If Me.chkSelected.Visible = True Then 'Allows recordselectors to pick resource records for updates
Dim i As Integer, SelectDirection As String, SelectNumber As Integer
SelectNumber = Me.SelHeight 'the number of records chkSelected
SelectDirection = "Up" 'default selection to start from bottom
If Me.CurrentRecord = Me.SelTop And Me.SelHeight = 1 Then
SelectDirection = "One" 'only 1 record chkSelected
ElseIf Me.CurrentRecord = Me.SelTop And Me.SelHeight > 1 Then
SelectDirection = "Down" 'selection was started from top
ElseIf Me.NewRecord = True Then 'user included blank new record in selection(shame on them :-)
DoCmd.GoToRecord acActiveDataObject, , acPrevious 'so lets go back one record
SelectNumber = SelectNumber - 1 'minus 1 from the no. chkSelected & stick to default up direction
End If
'MsgBox SelectDirection
Do While i < SelectNumber
If IsNull(Me.ID) Then Exit Do
If Me.chkSelected = True Then '
Me.chkSelected = False
Else
Me.chkSelected = True
End If
If (Me.CurrentRecord = 1 And Me.NewRecord = -1) Or Me.NewRecord = -1 Or i = SelectNumber - 1 Then
Me.Refresh
Exit Do 'we are out of the record range (all done)
End If
If SelectDirection = "Down" Then 'started from top move forward
DoCmd.GoToRecord acActiveDataObject, , acNext
ElseIf SelectDirection = "Up" Then 'started from bottom move Backward
DoCmd.GoToRecord acActiveDataObject, , acPrevious
End If
Me.Refresh 'refresh changes
i = i + 1 'increment I for loop
Loop
End If
FormClickerr:
If Val(Err) = 3101 Or Val(Err) = 2105 Then 'user caught trying to create a inadvertant
Me.Undo 'new record because a new record was in the selection
Resume Next
ElseIf Val(Err) <> 0 Then
MsgBox Err.Number & " " & Err.Description
End If
End Sub