Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2004
    Posts
    43

    Arrow Unanswered: deleting problem

    why is it that when i delete a record the first record is deleted not the one that is in the combobox and name?

    i have a combobox customerid to choose and when i click delete the id is not followed the first record in the table is deleted...

    Private Sub accept_Click()
    DoCmd.RunSQL "delete from customer where customerid=cmbcustomerid and name=txtname;"
    DoCmd.close
    End Sub

  2. #2
    Join Date
    Jun 2004
    Posts
    55
    The SQL is wrong I think. I'm not sure because I don't really use the Run SQL command but try this anyway:

    DoCmd.RunSQL "delete from customer where customerid= '" & cmbcustomerid "' and name= '" & txtname & "';"


    Or

    DoCmd.RunSQL "delete from customer where customerid= [Forms]![FormName]![cmbcustomerid] and name= [Forms]![FormName]![txtname];"
    Last edited by dwil2g1; 06-17-04 at 14:47.

  3. #3
    Join Date
    Dec 2003
    Location
    Dallas, TX
    Posts
    1,004
    Quote Originally Posted by oeuf85
    why is it that when i delete a record the first record is deleted not the one that is in the combobox and name?

    i have a combobox customerid to choose and when i click delete the id is not followed the first record in the table is deleted...

    Private Sub accept_Click()
    DoCmd.RunSQL "delete from customer where customerid=cmbcustomerid and name=txtname;"
    DoCmd.close
    End Sub

    Try this...comes right from my database that Deletes the record and then requeries the form and control.

    Code:
    Private Sub cmbDeleteRecord_Click()
    On Error GoTo Err_cmbDeleteRecord_Click
    
    
        DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
        DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
        DoCmd.Requery "sfrmJobChargesViewAll"
        DoCmd.Requery "JobID"
        
    Exit_cmbDeleteRecord_Click:
        Exit Sub
    
    Err_cmbDeleteRecord_Click:
        MsgBox Err.Description
        Resume Exit_cmbDeleteRecord_Click
        
    End Sub
    Bud

  4. #4
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    DoCmd.RunSQL "DELETE * FROM customer WHERE customerid= " & [Forms]![FormName]![cmbcustomerid] & "AND name= '" & [Forms]![FormName]![txtname] &"';"

Posting Permissions

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