V
vbnetman via AccessMonster.com
How can I delete a listbox row. Something like If ....then....Test_lbx.column
(0) = 0 ?
Thank you,
vb
(0) = 0 ?
Thank you,
vb
Tom said:You can clear all selected items in a listbox with the multiselect property
set to simple or extended with code similar to the following. This example is
for a listbox named "lboProjects":
Dim intCurrCat As Integer
For intCurrCat = 0 To Me.lboProjects.ListCount - 1
Me.lboProjects.Selected(intCurrCat) = False
Next intCurrCat
I suppose if you only wanted to clear a specific selection, and you know
it's row count (keeping in mind the zero based count), then you could simply
clear that one selection.
Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________
[quoted text clipped - 4 lines]How can I delete a listbox row. Something like If ....then....Test_lbx.column
(0) = 0 ?
Tom said:You can clear all selected items in a listbox with the multiselect property
set to simple or extended with code similar to the following. This example is
for a listbox named "lboProjects":
Dim intCurrCat As Integer
For intCurrCat = 0 To Me.lboProjects.ListCount - 1
Me.lboProjects.Selected(intCurrCat) = False
Next intCurrCat
I suppose if you only wanted to clear a specific selection, and you know
it's row count (keeping in mind the zero based count), then you could simply
clear that one selection.
Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________
[quoted text clipped - 4 lines]How can I delete a listbox row. Something like If ....then....Test_lbx.column
(0) = 0 ?
What's the RowSourceType of the ListBox?
If it's a query, you either have to delete it from the table, or use an
appropriate Where clause on the query (and requery the list box).
If it's a value list, there's a RemoveItem method you can use.
[quoted text clipped - 3 lines]How can I delete a listbox row. Something like If
....then....Test_lbx.column
The RowSourceType is simply a table.
What's the RowSourceType of the ListBox?
If it's a query, you either have to delete it from the table, or
use an appropriate Where clause on the query (and requery the list
box).
If it's a value list, there's a RemoveItem method you can use.
[quoted text clipped - 3 lines]How can I delete a listbox row. Something like If
....then....Test_lbx.column
Bob said:The RowSourceType is simply a table.
So, do you want to delete the item from the table, or simply have it
excluded from the list, after you've created an entry in a junction
table?
If the latter, decode my email, drop me a note and I'll send you a
tiny demo that handles 2 listboxes, and moves entries from one to the
other, for populating or clearing a junction table.
Q
What's the RowSourceType of the ListBox?
[quoted text clipped - 9 lines]
vb
Q,
Either way i think would work however deleting from the underlying
table would be better.
vb
Bob said:The RowSourceType is simply a table.
So, do you want to delete the item from the table, or simply have
it excluded from the list, after you've created an entry in a
junction table?
If the latter, decode my email, drop me a note and I'll send you a
tiny demo that handles 2 listboxes, and moves entries from one to
the other, for populating or clearing a junction table.
Q
[quoted text clipped - 9 lines]What's the RowSourceType of the ListBox?
Tom said:Please clarify what you are trying to accomplish. Are you trying to clear the
selected items in a multiselect listbox (in which case the code I provided
should work), or are you trying to remove one or more items from the list? If
you are trying to remove one or more items, and your list box is based on a
query, then either remove the record directly from the table, or add the
appropriate criteria to the query that serves as the RowSource for your list
box.
Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________
[quoted text clipped - 11 lines]TW
Here's what I tried. I replaced your list box name with mine and ran it. I
Bob said:Q,
Either way i think would work however deleting from the underlying
table would be better.
vb
Ok, in the afterupdate event procedure of the listbox, run a query
that deletes the row, then command the listbox to requery itself.
Docmd.runsql "delete * from table " & _
"where [fieldname] = """ & me.listbox.value & """;"
me.listboxname.requery
The RowSourceType is simply a table.
[quoted text clipped - 13 lines]
vb
Q,
Private Sub PartsSetupPartsAssignment_lbx_AfterUpdate()
DoCmd.RunSQL "delete * from table " & _
"where [RefUnitId] = """ & Me.PartsSetupPartsAssignment_lbx.Value
& """;" Me.PartsSetupPartsAssignment_lbx.Requery
I get a syntax error
Bob said:Q,
Either way i think would work however deleting from the
underlying table would be better.
vb
Ok, in the afterupdate event procedure of the listbox, run a query
that deletes the row, then command the listbox to requery itself.
Docmd.runsql "delete * from table " & _
"where [fieldname] = """ & me.listbox.value & """;"
me.listboxname.requery
[quoted text clipped - 13 lines]The RowSourceType is simply a table.
Bob said:[quoted text clipped - 3 lines]Q,
Private Sub PartsSetupPartsAssignment_lbx_AfterUpdate()I get a syntax error
[RefUnitId] is a number?
"where [RefUnitId] = """ & Me.PartsSetupPartsAssignment_lbx.Value &
""";"
is for text.
"where [RefUnitId] = " & Me.PartsSetupPartsAssignment_lbx.Value & ";"
would be the proper syntax for a number.
Hope that helps.
Q,
Either way i think would work however deleting from the [quoted text clipped - 14 lines]
vb
Bob said:[quoted text clipped - 3 lines]Q,
Private Sub PartsSetupPartsAssignment_lbx_AfterUpdate()I get a syntax error
[RefUnitId] is a number?
"where [RefUnitId] = """ & Me.PartsSetupPartsAssignment_lbx.Value &
""";"
is for text.
"where [RefUnitId] = " & Me.PartsSetupPartsAssignment_lbx.Value & ";"
would be the proper syntax for a number.
Hope that helps.
Q,
Either way i think would work however deleting from the [quoted text clipped - 14 lines]
vb
Both RefUnitId and RefPartNo are text fields
Bob said:[quoted text clipped - 3 lines]Q,
Private Sub PartsSetupPartsAssignment_lbx_AfterUpdate()I get a syntax error
[RefUnitId] is a number?
"where [RefUnitId] = """ & Me.PartsSetupPartsAssignment_lbx.Value
& """;"
is for text.
"where [RefUnitId] = " & Me.PartsSetupPartsAssignment_lbx.Value &
";" would be the proper syntax for a number.
Hope that helps.
[quoted text clipped - 14 lines]Q,
Either way i think would work however deleting from the
Bob said:Both RefUnitId and RefPartNo are text fields
Ok, lets start over...
the SQL clause should begin
Docmd.runsql "delete * from table " & _
We need the table's real name.
Then we need the value of the Control Source field from the listbox
I assume it'll be the ID not the description
"WHERE [RefUnitId] = """ & _
Me.PartsSetupPartsAssignment_lbx & """ & _
Then we would need the field name and value from the combobox that
sets the other side of the junction table.
"AND [RefPartNo] = """ & me.[whatever the combobox is called] &
""";"
The _ is a line continuation character that says treat the next line
as a continuation of this one.
Q,
Private Sub PartsSetupPartsAssignment_lbx_AfterUpdate() [quoted text clipped - 17 lines]
vb
Bob said:Both RefUnitId and RefPartNo are text fields
Ok, lets start over...
the SQL clause should begin
Docmd.runsql "delete * from table " & _
We need the table's real name.
Then we need the value of the Control Source field from the listbox
I assume it'll be the ID not the description
"WHERE [RefUnitId] = """ & _
Me.PartsSetupPartsAssignment_lbx & """ & _
Then we would need the field name and value from the combobox that
sets the other side of the junction table.
"AND [RefPartNo] = """ & me.[whatever the combobox is called] &
""";"
The _ is a line continuation character that says treat the next line
as a continuation of this one.
Q,
Private Sub PartsSetupPartsAssignment_lbx_AfterUpdate() [quoted text clipped - 17 lines]
vb
DoCmd.RunSQL "delete * from fits " & _Q,
DoCmd.RunSQL "delete * from fits " & _
"where [RefUnitId] = """ & _
Me.PartsSetupPartsAssignment_lbx & _
"AND [RefPartNo] = """ & Me.PartsSetupUnitID_Cbx & _
""";"
The table's real name is fits. Field name of the combo is
PartsSetupUnitID_Cbx. Control source of the listbox is refUnitId.
This is the code I used but I get a syntax error. I'm not well
versed...I must be missing something.
vb
Bob said:[quoted text clipped - 10 lines]DoCmd.RunSQL "delete * from fits " & _
"where [RefUnitId] = """ & _
Me.PartsSetupPartsAssignment_lbx & _
""" AND [RefPartNo] = """ & Me.PartsSetupUnitID_Cbx & _
""";"
You were missing a couple of quotes and a space in front of the AND
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.