delete code problem.help needed urgently

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • itoxic07
    New Member
    • Aug 2007
    • 2

    #1

    delete code problem.help needed urgently

    my code:
    rs!empnamee = Trim(Text1.Text )
    On Error Resume Next

    con.Execute "delete from paymentemployac c where empnamee='" & Trim(Text1.Text ) & "'"
    MsgBox "Employ deleted"

    Call sClear(Me)

    it deletes the records mentioned in text1
    but, it allways messages employ deleted but there is no such records
    so, please help me with good working code
    1>which should give message when record not found
    2>which should give message when record is deleted
    3>which should delete the records written in textbox including duplicate names
  • MikeTheBike
    Recognized Expert Contributor
    • Jun 2007
    • 640

    #2
    Originally posted by itoxic07
    my code:
    rs!empnamee = Trim(Text1.Text )
    On Error Resume Next

    con.Execute "delete from paymentemployac c where empnamee='" & Trim(Text1.Text ) & "'"
    MsgBox "Employ deleted"

    Call sClear(Me)

    it deletes the records mentioned in text1
    but, it allways messages employ deleted but there is no such records
    so, please help me with good working code
    1>which should give message when record not found
    2>which should give message when record is deleted
    3>which should delete the records written in textbox including duplicate names
    Hi

    Perhaps you could use the RecordsAffected property of the Execute method!?

    MTB

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Just a more-or-less unrelated comment. It looks as though this code will fail if you hit a name containing an apostrophe. For example, "O'Reilly". You might want to have a look at the index of tips and tricks in the Access forum. I believe it contains an entry which talks about string delimiters, including this sort of pitfall.

      Comment

      • fplesco
        New Member
        • Jul 2007
        • 82

        #4
        Originally posted by itoxic07
        my code:
        rs!empnamee = Trim(Text1.Text )
        On Error Resume Next

        con.Execute "delete from paymentemployac c where empnamee='" & Trim(Text1.Text ) & "'"
        MsgBox "Employ deleted"

        Call sClear(Me)

        it deletes the records mentioned in text1
        but, it allways messages employ deleted but there is no such records
        so, please help me with good working code
        1>which should give message when record not found
        2>which should give message when record is deleted
        3>which should delete the records written in textbox including duplicate names
        Hi -

        What are you trying to do in this code?
        Code:
        rs!empnamee = Trim(Text1.Text)
        I guess, this should be
        Code:
        Text1.Text = Trim(rs!empnamee)
        As per your problem, all you have to do is to search first the record. Then, if you find it, issue a delete command.
        Code:
        con.Execute "Select * from paymentemployacc where empnamee='" & Trim(Text1.Text) & "'"
        If not <Recordset variable>.EOF then
                RecordFound = True
        Else
               RecordFound = False
        End if
        If RecordFound = True then 
            con.Execute "delete from paymentemployacc where empnamee='" & Trim   (Text1.Text) & "'"
            MsgBox "Employ deleted"
        Else
            Msgbox "No record found!"
        End if

        Comment

        Working...