Connecting Tech Pros Worldwide Forums | Help | Site Map

delete table based value from listbox

Newbie
 
Join Date: Mar 2008
Posts: 2
#1: Mar 28 '08
Hi everyone,

i've a problem when i trying to delete a record in table based a value from listbox. Can someone give me an idea on it...

Thanks.

Newbie
 
Join Date: Mar 2008
Location: Portland, Oregon
Posts: 19
#2: Mar 28 '08

re: delete table based value from listbox


Put this code in the onclick event of a button. You'll need to change the names to match your field name, your tablename and your listboxname. Be sure the field you reference in your table is the same field that is contained in your listbox.

Dim curLstVal
dim strSql as string

curLstVal= me.mylistboxname

strSql = "Delete from tblMyTable where fldMyfield = " & curLstVal & "

docmd.runsql(strSql)

msgbox"Record deleted"
Newbie
 
Join Date: Mar 2008
Location: Portland, Oregon
Posts: 19
#3: Mar 28 '08

re: delete table based value from listbox


Quote:

Originally Posted by itasking

Hi everyone,

i've a problem when i trying to delete a record in table based a value from listbox. Can someone give me an idea on it...

Thanks.

I should have added, another way to do it is this (first get your listbox value like in the last example):
dim curVal
dim rs as recordset
dim strsql as string

curval=myListBox.value

strsql="Select * from myTable where myField = " & curVal & "

set rs= currentdb.openrecordset(strsql)

if not rs.eof then
'go on
else
exit sub
end if
with rs
.delete
end with

msgbox"Recordset deleted"
Reply