Add & Delete List Box Records

M

Mark K

I am fairly new to Access programing a was hope someone
could point me in the right direction. I have a simple
form consisting of an unbound text box that will allow a
small value (code) to be typed and added to a master code
list box that has an underlying table (tblSystemCodes)
using an ADD button. After the the value is added I need
the list box to refresh to show all the records from the
tblSystemCodes. Also need to Delete the selected value in
the list box when the Delete button is clicked.

I have the 'Add' button working to the point where the new
record is added to the table but the list box does not
reflect this. I know there must be a simple solution but
I'm not finging it.

Thanks
 
H

Howard Brody

lstListBoxName.Refres

----- Mark K wrote: ----

I am fairly new to Access programing a was hope someone
could point me in the right direction. I have a simple
form consisting of an unbound text box that will allow a
small value (code) to be typed and added to a master code
list box that has an underlying table (tblSystemCodes
using an ADD button. After the the value is added I need
the list box to refresh to show all the records from the
tblSystemCodes. Also need to Delete the selected value in
the list box when the Delete button is clicked

I have the 'Add' button working to the point where the new
record is added to the table but the list box does not
reflect this. I know there must be a simple solution but
I'm not finging it

Thanks
 
D

Dan Artuso

Hi,
After you've added the new record to the table:

Me.yourListBox.Requery

To delete an entry (assuming multi select is set to none)

Dim strSql As String
strSql = "Delete From tblSystemCodes Where code = " & Me.yourListBox

CurrentDb.Execute strSql, dbFailOnError

If the 'code' is text as opposed to a number,
strSql = "Delete From tblSystemCodes Where code = '" & Me.yourListBox & "'"

Substutute the correct names for the listbox and the table field.

HTH
Dan Artuso, MVP
 
G

Guest

Thanks guys for setting me straight.
-----Original Message-----
Hi,
After you've added the new record to the table:

Me.yourListBox.Requery

To delete an entry (assuming multi select is set to none)

Dim strSql As String
strSql = "Delete From tblSystemCodes Where code = " & Me.yourListBox

CurrentDb.Execute strSql, dbFailOnError

If the 'code' is text as opposed to a number,
strSql = "Delete From tblSystemCodes Where code = '" & Me.yourListBox & "'"

Substutute the correct names for the listbox and the table field.

HTH
Dan Artuso, MVP




.
 

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