Listbox deletion

  • Thread starter vbnetman via AccessMonster.com
  • Start date
V

vbnetman via AccessMonster.com

How can I delete a listbox row. Something like If ....then....Test_lbx.column
(0) = 0 ?

Thank you,

vb
 
T

Tom Wickerath

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/
__________________________________________
 
V

vbnetman via AccessMonster.com

TW
Here's what I tried. I replaced your list box name with mine and ran it. I
set the lb multiselect property to simple.

Dim intCurrCat As Integer

For intCurrCat = 0 To Me.PartsSetupPartsAssignment_lbx.ListCount - 1

Me.PartsSetupPartsAssignment_lbx.Selected(intCurrCat) = False

Next intCurrCat

No success

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/
__________________________________________
How can I delete a listbox row. Something like If ....then....Test_lbx.column
(0) = 0 ?
[quoted text clipped - 4 lines]
 
V

vbnetman via AccessMonster.com

Note; the specific selection is unknown. It would simply be a selected item
(highlited)

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/
__________________________________________
How can I delete a listbox row. Something like If ....then....Test_lbx.column
(0) = 0 ?
[quoted text clipped - 4 lines]
 
D

Douglas J. Steele

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.
 
V

vbnetman via AccessMonster.com

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.
How can I delete a listbox row. Something like If
....then....Test_lbx.column
[quoted text clipped - 3 lines]
 
B

Bob Quintal

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?

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.
How can I delete a listbox row. Something like If
....then....Test_lbx.column
[quoted text clipped - 3 lines]
 
V

vbnetman via AccessMonster.com

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
What's the RowSourceType of the ListBox?
[quoted text clipped - 9 lines]

vb
 
T

Tom Wickerath

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/
__________________________________________
 
B

Bob Quintal

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


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]
 
V

vbnetman via AccessMonster.com

TW,
The listbox is based simply on a table. I set the multiselect property to
simple, ran the code and had no result. In my application, I need to assume
that a user is going to make an error. Thus, I need to allow for deletions. I
think it may be best to make a deletion at the table but I'm not sure how to
do this. The end result needs to be a selected item in the listbox removed.

vb

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/
__________________________________________
TW
Here's what I tried. I replaced your list box name with mine and ran it. I
[quoted text clipped - 11 lines]
 
V

vbnetman via AccessMonster.com

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
The RowSourceType is simply a table.
[quoted text clipped - 13 lines]

vb
 
B

Bob Quintal

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

[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.
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]
 
V

vbnetman via AccessMonster.com

Q,
I still show a syntax error in the FROM clause. The problem may be here....
the list box has 2 fields; RefUnitID and RefPartNo. It's based on a junction
table. I did not mention the 2 fields which may be where the problem lies


Bob said:
Q,
Private Sub PartsSetupPartsAssignment_lbx_AfterUpdate()
[quoted text clipped - 3 lines]
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
 
V

vbnetman via AccessMonster.com

Both RefUnitId and RefPartNo are text fields

Bob said:
Q,
Private Sub PartsSetupPartsAssignment_lbx_AfterUpdate()
[quoted text clipped - 3 lines]
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
 
B

Bob Quintal

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.
Bob said:
Q,
Private Sub PartsSetupPartsAssignment_lbx_AfterUpdate()
[quoted text clipped - 3 lines]
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]
 
V

vbnetman via AccessMonster.com

Q,
I have not deserted this post. I just got hit with a list of chores. I will
try to followup with this a bit later tonite.

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
 
V

vbnetman via AccessMonster.com

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:
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
 
B

Bob Quintal

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
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
 
V

vbnetman via AccessMonster.com

Houston, we have a problem. Is there a way that I can send you the portion of
the db that's giving me a fit?

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
 

Ask a Question

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.

Ask a Question

Top