我有一个带有数据表视图的表单我想将此表单用作列表框(多选扩展),所以当我单击它使用的表单中的每个记录/字段时(清除选择功能)用于未选择的其他记录并选择我已经关注的记录,现在的问题是在运行清除选择功能后单击每个字段时,它会转到第一条记录并且没有将光标移动到当前聚焦的记录。
似乎在代码下面
Me.Recordset.AbsolutePosition = Pos1
不起作用,也不会移动到当前的焦点记录。
完整的代码如下:
Private Sub P_Click()
On Error Resume Next
Dim ct As Control
Dim Cnt As Long, Rws As Long
Dim Pos1 As Long, Pos2 As Long
Pos1 = Me.Recordset.AbsolutePosition
Set ct = ActiveControl
' Clear other selections if Ctrl or Shift key
' is not simultaneously pressed.
If CtrlPressed = 0 And ShiftPressed = 0 Then
P_ClearSelections
Me.Recordset.AbsolutePosition = Pos1
Me.IsSelected = True
ct.SetFocus
GoTo ExitPoint
End If
If ShiftPressed > 0 Then
Rws = Me.SelHeight
If Rws > 1 Then
Pos2 = Me.SelTop - 1
For Cnt = Pos2 To Pos2 + Rws - 1
Me.Recordset.AbsolutePosition = Cnt
Me.IsSelected = True
Next
End If
GoTo ExitPoint
End If
Me.IsSelected = True
ExitPoint:
' Save the status
Me.Dirty = False
' Update display in SF_Selected
Me.Parent("SF_Selected").Requery
ActiveControl.SelLength = 0
Set ct = Nothing
On Error GoTo 0
End Sub
功能清除选择如下;
Public Sub P_ClearSelections()
On Error Resume Next
DoCmd.Echo False
' Clear all check boxes
CurrentDb.Execute "UPDATE tblItems " & _
"SET IsSelected = False;", dbFailOnError
Me.Requery
DoCmd.Echo True
On Error GoTo 0
End Sub