Problem deleting record

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DENALISSA
    New Member
    • Mar 2008
    • 3

    Problem deleting record

    I keep getting a Run-Time everytime I try deleting a record: My code is this:

    Code:
    Private Sub cmdDelete_Click()
    Dim sql As String
    sql = "Delete * from Agentinfo where AGENTID =" & txtAgtId.Text 
    MsgBox (sql)
    Dim cn As New ADODB.Connection
    cn.ConnectionString = "DSN=Agents"
    Dim rs As New ADODB.Recordset
    cn.Open
    Set rs = cn.Execute(sql)
    MsgBox ("Record successfully deleted")
    txtAgtId.Text = ""
    txtBranch.Text = ""
    txtFirstName.Text = ""
    txtLastName.Text = ""
    txtDateHired.Text = ""
    txtStatus.Text = ""
    cn.Close
    End Sub
    But I am getting an error message saying "Too Few Parameters. Expected 1"
  • mafaisal
    New Member
    • Sep 2007
    • 142

    #2
    Hello

    Try This

    Code:
    Dim sql As String
    sql = "Delete  from Agentinfo where AGENTID =" & txtAgtId.Text 
    MsgBox (sql)
    Dim cn As New ADODB.Connection
    cn.ConnectionString = "DSN=Agents"
    cn.Open
    cn.Execute(sql)
    MsgBox ("Record successfully deleted")
    txtAgtId.Text = ""
    txtBranch.Text = ""
    txtFirstName.Text = ""
    txtLastName.Text = ""
    txtDateHired.Text = ""
    txtStatus.Text = ""
    cn.Close
    Also When U Post Question Clearly Specify Which Location Error is coming

    So Here Experts Have easily identify that

    Faisal

    Comment

    • DENALISSA
      New Member
      • Mar 2008
      • 3

      #3
      Originally posted by DENALISSA
      I keep getting a Run-Time everytime I try deleting a record: My code is this:

      Code:
      Private Sub cmdDelete_Click()
      Dim sql As String
      sql = "Delete * from Agentinfo where AGENTID =" & txtAgtId.Text 
      MsgBox (sql)
      Dim cn As New ADODB.Connection
      cn.ConnectionString = "DSN=Agents"
      Dim rs As New ADODB.Recordset
      cn.Open
      Set rs = cn.Execute(sql)
      MsgBox ("Record successfully deleted")
      txtAgtId.Text = ""
      txtBranch.Text = ""
      txtFirstName.Text = ""
      txtLastName.Text = ""
      txtDateHired.Text = ""
      txtStatus.Text = ""
      cn.Close
      End Sub
      But I am getting an error message saying "Too Few Parameters. Expected 1"
      Thanks for your information, I am new to this forum, however when I tried the code you gave me, I am getting a new error:
      Run-time error '-2147217904 (80040e10)': Microsoft [ODBC Microsoft Access Driver] Syntax error in string in query expression 'AGENTID = A04123"

      Comment

      • DENALISSA
        New Member
        • Mar 2008
        • 3

        #4
        Thanks for your information, I am new to this forum, however when I tried the code you gave me, I am getting a new error:
        Run-time error '-2147217904 (80040e10)': Microsoft [ODBC Microsoft Access Driver] Syntax error in string in query expression 'AGENTID = A04123"

        --------------------------------------------------------------------------------

        Comment

        • wireshark
          New Member
          • Mar 2008
          • 29

          #5
          Originally posted by DENALISSA
          Thanks for your information, I am new to this forum, however when I tried the code you gave me, I am getting a new error:
          Run-time error '-2147217904 (80040e10)': Microsoft [ODBC Microsoft Access Driver] Syntax error in string in query expression 'AGENTID = A04123"
          change your query :
          sql = "Delete * from Agentinfo where AGENTID =" & txtAgtId.Text
          with
          sql = "Delete * from Agentinfo where AGENTID = '" & txtAgtId.Text & "'"

          Comment

          • obkfixx
            New Member
            • Mar 2008
            • 19

            #6
            Try this:

            Private Sub cmdDelete_Click ()

            Dim cn As New ADODB.Connectio n

            cn.ConnectionSt ring = "DSN=Agents "

            Dim rs As New ADODB.Recordset
            cn.Open

            Set rs = cn.Execute( "Delete * from Agentinfo where AGENTID = '"& txtAgtId.Text &"'")
            MsgBox ("Record successfully deleted")
            txtAgtId.Text = ""
            txtBranch.Text = ""
            txtFirstName.Te xt = ""
            txtLastName.Tex t = ""
            txtDateHired.Te xt = ""
            txtStatus.Text = ""
            cn.Close
            End Sub

            Comment

            • lotus18
              Contributor
              • Nov 2007
              • 865

              #7
              [CODE=vb]Private Sub cmdDelete_Click ()
              Dim sql As String
              sql = "Delete * from Agentinfo where AGENTID=" & txtAgtId.Text
              MsgBox (sql)
              Dim cn As New ADODB.Connectio n
              cn.ConnectionSt ring = "DSN=Agents "
              cn.Open
              cn.Execute(sql)
              MsgBox ("Record successfully deleted")
              txtAgtId.Text = ""
              txtBranch.Text = ""
              txtFirstName.Te xt = ""
              txtLastName.Tex t = ""
              txtDateHired.Te xt = ""
              txtStatus.Text = ""
              cn.Close
              End Sub[/CODE]

              What is the datatype of AGENTID?

              Rey Sean

              Comment

              • mafaisal
                New Member
                • Sep 2007
                • 142

                #8
                Hello

                Try This
                Code:
                Dim sql As String
                sql = "Delete *  from Agentinfo where AGENTID ='" & txtAgtId.Text & "'"    '*** " & txtAgentid  - Change to  '" & txtAgentID & "'
                MsgBox (sql)
                Dim cn As New ADODB.Connection
                cn.ConnectionString = "DSN=Agents"
                cn.Open
                cn.Execute(sql)
                MsgBox ("Record successfully deleted")
                txtAgtId.Text = ""
                txtBranch.Text = ""
                txtFirstName.Text = ""
                txtLastName.Text = ""
                txtDateHired.Text = ""
                txtStatus.Text = ""
                cn.Close
                in Ur code AgentId as Integer in Line 2

                I think AgentId is Text(String) Bcoz in ur code agentid = A04123
                Also Check ur table if AgentId is Number or text
                if Number u given text is not number that is string thats problem
                check
                if number change query to
                Code:
                sql = "Delete *  from Agentinfo where AGENTID =" & val(txtAgtId.Text)
                Try ablove code

                Faisal

                Originally posted by DENALISSA
                Thanks for your information, I am new to this forum, however when I tried the code you gave me, I am getting a new error:
                Run-time error '-2147217904 (80040e10)': Microsoft [ODBC Microsoft Access Driver] Syntax error in string in query expression 'AGENTID = A04123"
                Last edited by mafaisal; Mar 23 '08, 04:12 PM. Reason: Added More

                Comment

                Working...