Results 1 to 6 of 6

Thread: Delete Button

  1. #1
    Join Date
    Apr 2013
    Posts
    3

    Unanswered: Delete Button

    Hi guys, I have an Add button using this code:
    Private Sub btnAdd_Click()
    Dim dbFilmi As dao.Database
    Dim rstInfoTBL As dao.Recordset

    Set dbFilmi = CurrentDb
    Set rstInfoTBL = dbFilmi.OpenRecordset("InfoTBL")

    rstInfoTBL.AddNew
    rstInfoTBL("ID").Value = Me.txtID
    rstInfoTBL("Name").Value = Me.txtName
    rstInfoTBL("DOB").Value = Me.txtDateFrom
    rstInfoTBL.Update
    rstInfoTBL.Close

    End Sub

    And now i'm trying to create a delete button that deletes the info i type in the fields some ideas ?

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Delete the whole row identified by Me.txtID or set some fields in that row to null?
    Have a nice day!

  3. #3
    Join Date
    Apr 2013
    Posts
    3
    I want to delete the whole row

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Try this:
    Code:
    Private Sub Command_Delete_Click()
    
        CurrentDb.Execute "DELETE FROM InfoTBL WHERE ID = " & Me.txtID, dbFailOnError
    
    End Sub
    If ID is not numeric, use:
    Code:
        CurrentDb.Execute "DELETE FROM InfoTBL WHERE ID = '" & Me.txtID & "'", dbFailOnError
    Have a nice day!

  5. #5
    Join Date
    Apr 2013
    Posts
    3
    ID is Auto/number i forgot to say that
    // EDIT: the code you gave me works perfect tnx a million
    Last edited by guilpter; 04-28-13 at 16:56.

  6. #6
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •