Removing one item from list box

D

Design by Sue

I have created a form with a combo box (PartNumberCombo) that, using a table
as its row source, the user can select an available Part Number and by
clicking on a button this Part Number is added to a List Box (ListBox). (I
am simplifying this so hopefully I have included enough so someone can get me
started.) I need to create a button so that the user can select one of the
items in the list box and remove only the selected item from the list.

Help!
 
A

Arvin Meyer [MVP]

Essentially. you do it similar to the way you've added it.

If you do not want to remove it permanently from your database, you need to
create a temporary table to connect to the list box. To add items to the
list box, you add items to the table and requery the list box. To delete
items you delete from the table and requery the list box. The syntax for the
SQL statements are:

To Add:

Dim strSQL As String

strSQL = "INSERT INTO tmpTableName ( [Part Number])"VALUES ('" &
Me.PartNumberCombo & "');"
CurrentDb.Execute strSQL
Me.PartNumberCombo.Requery

To Delete:

Dim strSQL As String

strSQL = "DELETE * FROM tmpTableName WHERE [Part Number] = '" &
Me.PartNumberCombo & "';"
CurrentDb.Execute strSQL
Me.PartNumberCombo.Requery
 
D

Design by Sue

You are good. I do have this list box connected to columns in my table
(PartSuffixTbl) and when a part number is added to the list box, the code
adds a selected line number (selected from another combo box with a row
source of LineTbl) and the employee's id (from a Module) to columns in the
table (TempID and TempLine). - What happens is after the user inputs all
part numbers to be assigned to a line, there is a button that when clicked,
adds the line number and employee ID to the columns ID and Line and the
temporary numbers are removed from TempID and TempLine. This list box allows
the user to enter a bunch of parts before finalizing the assignment. So what
I have to do is removed the numbers from the TempID and TempLine columns of
the table (PartSuffixTbl).

To make it a bit more complex, I am using a query throughout the form to
combine the Part Numbers and Suffixes that are in separate columns to one
number, ie PartNumber-Suffix (12345-1). I do have all of the columns
included in the column count on the list box (ListBox) so I should be able to
refer to them. (right)

I have only limited knowledge of Access but an learning (I only get asked to
do this about once a year and forget about 1/2 of what I learned)

Thanks for trying to help!

Sue

Arvin Meyer said:
Essentially. you do it similar to the way you've added it.

If you do not want to remove it permanently from your database, you need to
create a temporary table to connect to the list box. To add items to the
list box, you add items to the table and requery the list box. To delete
items you delete from the table and requery the list box. The syntax for the
SQL statements are:

To Add:

Dim strSQL As String

strSQL = "INSERT INTO tmpTableName ( [Part Number])"VALUES ('" &
Me.PartNumberCombo & "');"
CurrentDb.Execute strSQL
Me.PartNumberCombo.Requery

To Delete:

Dim strSQL As String

strSQL = "DELETE * FROM tmpTableName WHERE [Part Number] = '" &
Me.PartNumberCombo & "';"
CurrentDb.Execute strSQL
Me.PartNumberCombo.Requery
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


Design by Sue said:
I have created a form with a combo box (PartNumberCombo) that, using a
table
as its row source, the user can select an available Part Number and by
clicking on a button this Part Number is added to a List Box (ListBox).
(I
am simplifying this so hopefully I have included enough so someone can get
me
started.) I need to create a button so that the user can select one of
the
items in the list box and remove only the selected item from the list.

Help!
 

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