Delete a row from a listbox (1 Viewer)

faz88

Registered User.
Local time
Today, 00:09
Joined
Mar 31, 2008
Messages
34
I have several listboxs on my form , How do i delete the row i select?
 

ShaneMan

Registered User.
Local time
Yesterday, 16:09
Joined
May 9, 2005
Messages
1,224
I have several listboxs on my form , How do i delete the row i select?

Hey Faz,

I did a little bit of a search and found this question and answer that seems to be what your looking for, so give this a try and see if it does.

John Nurick (Microsoft MVP) is the individual who gave the answer:

Dim strSQL As String

strSQL = "DELETE * FROM MyTable WHERE KeyField=""" _
& Me.lbXXX.Value & """;"
CurrentDB.Execute strSQL
Me.lbXXX.Requery

You'll need to replace
MyTable with the name of the table
KeyField with the name of the field in the table corresponding
to the bound column in the listbox
lbXXX with the name of the listbox (*not* the name of the field
the listbox is bound to).

HTH,
Shane
 

faz88

Registered User.
Local time
Today, 00:09
Joined
Mar 31, 2008
Messages
34
Hi, thanks alot, it worked!


Hey Faz,

I did a little bit of a search and found this question and answer that seems to be what your looking for, so give this a try and see if it does.

John Nurick (Microsoft MVP) is the individual who gave the answer:

Dim strSQL As String

strSQL = "DELETE * FROM MyTable WHERE KeyField=""" _
& Me.lbXXX.Value & """;"
CurrentDB.Execute strSQL
Me.lbXXX.Requery

You'll need to replace
MyTable with the name of the table
KeyField with the name of the field in the table corresponding
to the bound column in the listbox
lbXXX with the name of the listbox (*not* the name of the field
the listbox is bound to).

HTH,
Shane
 

smile

Registered User.
Local time
Yesterday, 16:09
Joined
Apr 21, 2006
Messages
212
I have tried this code and it seems to work:

PHP:
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordSet("Select * from [tblEmployees]")
rs.FindFirst "[EmployeesID] =" & Me!List0
rs.Delete
Me.List0.Requery

But works for listbox only

Replace List0 with your listbox name
Replace tblEmployees with your table name
Replace EmployeesID with your ID fieldname.

Full tread http://www.tek-tips.com/viewthread.cfm?qid=1084498&page=7
 

Users who are viewing this thread

Top Bottom