Delete record with a button

  • Thread starter Thread starter Bernd Smits
  • Start date Start date
B

Bernd Smits

Hi,
I've a combobox with inside a list of values. Now I would like that, when I
select a value (equivalent to a number of record in an associated table) of
the combobox, I click on a button and the value in the combobox disappears,
and also the associated record in the table is canceled.
Is it possible? How?
Thanks
Bernd
 
Hi,
I assume your combo is populated from the table and that the bound column
is the primary key of the table?

If so...

Dim strSql as String

strSql = "Delete From yourTable Where someField = " & Me.yourListBox
CurrentDb.Execute strSql,dbFailOnError

Me.yourListBox.Requery

Substitute the correct names of course for yourTable, someField and yourListBox

This WILL NOT work for multi-select listboxes
 
You will need to execute a Delete Query and then requery the ComboBox.

Check Access Help / Access VB Help on Delete Query / SQL String, the
OpenQuery or RunSQL or Execute Method to run the Query or SQL String and the
Requery Method.
 
Back
Top