delete table based value from listbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • itasking
    New Member
    • Mar 2008
    • 2

    delete table based value from listbox

    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.
  • Fiddler2
    New Member
    • Mar 2008
    • 19

    #2
    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.mylistboxnam e

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

    docmd.runsql(st rSql)

    msgbox"Record deleted"

    Comment

    • Fiddler2
      New Member
      • Mar 2008
      • 19

      #3
      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=myListBo x.value

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

      set rs= currentdb.openr ecordset(strsql )

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

      msgbox"Recordse t deleted"

      Comment

      Working...