请问如何使用复选框删除所有被选中的记录?
请帮忙修改以下代码,以达到效果。
Private Sub DeleteUser()
    Dim strSelectUsers As String
    Dim i As Integer    ' placeholder
    Set lvxObj = Me.ListView3.Object
    ' loop through the listview
    For i = lvxObj.ListItems.Count To 1 Step -1
        ' check to see if the item is checked, if so, remove it
        If lvxObj.ListItems(i).Checked = True Then
            strSelectUsers = lvxObj.SelectedItem
            DoCmd.SetWarnings False
            DoCmd.RunSQL " delete from usysUsers where fusername ='" & strSelectUsers & "'"
            DoCmd.SetWarnings True
            'lvxObj.ListItems.Remove (i)
        End If
    Next i
End Sub

解决方案 »

  1.   

    以上代码还只能删除一条被单击过得记录,我不知道checked值怎么取的到.应该要把strSelectUsers = lvxObj.SelectedItem 这句改掉
      

  2.   

    在listview 中如何使用复选框删除被选中的相关记录.
      

  3.   

    Private Sub DeleteUser()
        Dim strSelectUsers As String
        Dim i As Integer    ' placeholder
        Set lvxObj = Me.ListView3.Object
        ' loop through the listview
        For i = lvxObj.ListItems.Count To 1 Step -1
            ' check to see if the item is checked, if so, remove it
            If lvxObj.ListItems(i).Checked = True Then
                strSelectUsers = lvxObj.ListItems(i).Text
                DoCmd.SetWarnings False
                DoCmd.RunSQL " delete from usysUsers where fusername ='" & strSelectUsers & "'"
                DoCmd.SetWarnings True
                'lvxObj.ListItems.Remove (i)
            End If
        Next i
    End Sub