J
jenny
Hi,
I have a list box that is bound to a table with unique
key, but I wanted to deselect some items in the list box,
at the same time delete theose Items in the bound table
that were deselected in the list box. I used a recordset
(dbOpenDynaset) for the bound table,and using loop,
findfirst and findnext methods for search to match so
that the selected content is the same as the contents in
the table, then do a recordset.delete , right now I can
only delete items from the very first of the list box. if
I selected some other items, ie. 4th or 5th items in the
list box, and tried to delete,nothing happens. though
I've found the matching contents for deletion. Does
anyone know why it can only delete first row in the list
box, not some other rows?
I've pasted my codes in the following, if anybody can
help me to take a look at them, let me what's wrong with
them, it will be greated appreciated.
Thanks for any help.
Jenny
''''''''' the following codes are for list box deselecting
Private Sub lstHomeGIDRemove_DblClick(Cancel As Integer)
Dim db as database
Dim rstRemove As Recordset
Dim strCriteria As String
Dim intSub As Integer
Dim intRecordCount As Integer
Dim varRemoved As Variant
Dim varRemoved2 As Variant
Dim intID As Variant
Dim intCount2 As Integer
Set rstRemove = db.OpenRecordset
("TmpSpecificEmployer", dbOpenDynaset)
If Not rstRemove.EOF And Not rstRemove.BOF Then
For Each varRemoved In Me!
lstHomeGIDRemove.ItemsSelected()
intID = Me!lstHomeGIDRemove.Column(0,
varRemoved) ' look for id for the table to match
rstRemove.MoveLast
intRecordCount = rstRemove.RecordCount
rstRemove.MoveFirst
intCount2 = rstRemove!intCount
strCriteria = intCount2 = intID
rstRemove.FindFirst strCriteria
If Not rstRemove.NoMatch Then
rstRemove.Edit
rstRemove.Delete
rstRemove.Requery
Me.lstHomeGIDRemove.Requery
Exit Sub
Else
For intSub = 2 To intRecordCount
rstRemove.MoveNext
intCount2 = rstRemove!intCount
strCriteria = intCount2 = intID
rstRemove.FindNext strCriteria
If Not rstRemove.NoMatch Then
rstRemove.Edit
rstRemove.Delete
rstRemove.Requery
Me.lstHomeGIDRemove.Requery
Exit Sub
End If
Next intSub
End If
Next varRemoved
Else
MsgBox "There is no data in the list box. Please
select the year(s) from the combox first.",
vbInformation, "CQM"
Me.cboYear.SetFocus
Me.cboYear.Dropdown
End If
End Sub
I have a list box that is bound to a table with unique
key, but I wanted to deselect some items in the list box,
at the same time delete theose Items in the bound table
that were deselected in the list box. I used a recordset
(dbOpenDynaset) for the bound table,and using loop,
findfirst and findnext methods for search to match so
that the selected content is the same as the contents in
the table, then do a recordset.delete , right now I can
only delete items from the very first of the list box. if
I selected some other items, ie. 4th or 5th items in the
list box, and tried to delete,nothing happens. though
I've found the matching contents for deletion. Does
anyone know why it can only delete first row in the list
box, not some other rows?
I've pasted my codes in the following, if anybody can
help me to take a look at them, let me what's wrong with
them, it will be greated appreciated.
Thanks for any help.
Jenny
''''''''' the following codes are for list box deselecting
Private Sub lstHomeGIDRemove_DblClick(Cancel As Integer)
Dim db as database
Dim rstRemove As Recordset
Dim strCriteria As String
Dim intSub As Integer
Dim intRecordCount As Integer
Dim varRemoved As Variant
Dim varRemoved2 As Variant
Dim intID As Variant
Dim intCount2 As Integer
Set rstRemove = db.OpenRecordset
("TmpSpecificEmployer", dbOpenDynaset)
If Not rstRemove.EOF And Not rstRemove.BOF Then
For Each varRemoved In Me!
lstHomeGIDRemove.ItemsSelected()
intID = Me!lstHomeGIDRemove.Column(0,
varRemoved) ' look for id for the table to match
rstRemove.MoveLast
intRecordCount = rstRemove.RecordCount
rstRemove.MoveFirst
intCount2 = rstRemove!intCount
strCriteria = intCount2 = intID
rstRemove.FindFirst strCriteria
If Not rstRemove.NoMatch Then
rstRemove.Edit
rstRemove.Delete
rstRemove.Requery
Me.lstHomeGIDRemove.Requery
Exit Sub
Else
For intSub = 2 To intRecordCount
rstRemove.MoveNext
intCount2 = rstRemove!intCount
strCriteria = intCount2 = intID
rstRemove.FindNext strCriteria
If Not rstRemove.NoMatch Then
rstRemove.Edit
rstRemove.Delete
rstRemove.Requery
Me.lstHomeGIDRemove.Requery
Exit Sub
End If
Next intSub
End If
Next varRemoved
Else
MsgBox "There is no data in the list box. Please
select the year(s) from the combox first.",
vbInformation, "CQM"
Me.cboYear.SetFocus
Me.cboYear.Dropdown
End If
End Sub