Add & Delete List Box Records

  • Thread starter Thread starter Mark K
  • Start date Start date
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
 
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
 
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
 
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




.
 
Back
Top