Results 1 to 11 of 11

Thread: What is wrong with this?

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    35

    Resolved What is wrong with this?

    Code:
            Dim con As New ADODB.Connection
            Dim con_string As String
            Dim sql As String
            Dim rs As New ADODB.Recordset
            con_string = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\Documents and Settings\leightr\My Documents\culverflex.mdb;"
            con.Open(con_string)
            sql = "delete * from whoishere where userid = " & ComboBox1.Text & ""
            rs = con.Execute(sql)
    I get a Data Mismatch error on: rs = con.Execute(sql)
    Last edited by mousewonders; Sep 8th, 2007 at 07:29 PM.

  2. #2
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: What is wrong with this?

    Remove the * from the below line.

    vb Code:
    1. sql = "delete * from whoishere where userid = " & ComboBox1.Text & ""

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    35

    Re: What is wrong with this?

    Still a Data Mismatch error

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: What is wrong with this?

    shouldn't that be
    "delete from whoishere where userid = '" & ComboBox1.text & "'"
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    35

    Re: What is wrong with this?

    Yep Thanks a million!!

    Any clue how to move the record to another table before I delete it?

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: What is wrong with this?

    you should be able to do something like this, but i haven't tried it at all
    vb Code:
    1. "insert into othertable (select * from whoishere whereuserid = '" & ComboBox1.text & "'")"
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    35

    Re: What is wrong with this?

    It doesnt seem to work
    Code:
     Dim con As New ADODB.Connection
            Dim con_string As String
            Dim sql As String
            Dim sql1 As String
            Dim rs As New ADODB.Recordset
            con_string = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\Documents and Settings\leightr\My Documents\culverflex.mdb;"
            con.Open(con_string)
            sql1 = "insert into archive (select * from whoishere whereuserid = '" & ComboBox1.text & "'")"
            sql = "delete from whoishere where userid = '" & TextBox1.Text & "'"
            rs = con.Execute(sql)

  8. #8

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    35

    Re: What is wrong with this?

    Okay I got it working with the following... the only problem is now the delete will now work!! But if I remove the move sql the delete will work.

    Code:
    Dim con As New ADODB.Connection
            Dim con_string As String
            Dim move As String
            Dim Sql As String
            Dim rs As New ADODB.Recordset
            con_string = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\Documents and Settings\leightr\My Documents\culverflex.mdb;"
            con.Open(con_string)
            move = "INSERT INTO archive SELECT * FROM Whoishere WHERE userid = '" & TextBox1.Text & "'"
            Sql = "delete from whoishere where userid = '" & TextBox1.Text & "'"
            rs = con.Execute(move, Sql)

  9. #9

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    35

    Re: What is wrong with this?

    Okay.. I figured it out (again) I am not sure if this is the correct way of doing what I am doing.. but it works! I thought I would post the correct code.. maybe someone can re-write it the correct way?

    Code:
     Dim con As New ADODB.Connection
            Dim con_string As String
            Dim move As String
            Dim del As String
            Dim rs As New ADODB.Recordset
            Dim rss As New ADODB.Recordset
            con_string = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\Documents and Settings\leightr\My Documents\culverflex.mdb;"
            con.Open(con_string)
            move = "INSERT INTO archive SELECT * FROM whoishere WHERE userid = '" & TextBox.Text & "'"
            del = "DELETE * FROM whoishere WHERE userid = '" & TextBox.Text & "'"
            rs = con.Execute(move)
            del = "DELETE * FROM whoishere WHERE userid = '" & TextBox.Text & "'"
            rss = con.Execute(del)

  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: What is wrong with this?

    move = "INSERT INTO archive SELECT * FROM whoishere WHERE userid = '" & TextBox.Text & "'"
    del = "DELETE * FROM whoishere WHERE userid = '" & TextBox.Text & "'"
    rs = con.Execute(move)
    del = "DELETE * FROM whoishere WHERE userid = '" & TextBox.Text & "'"
    rss = con.Execute(del)
    you don't need the del = twice,other than that looks ok
    as it works, all is good
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  11. #11

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    35

    Re: What is wrong with this?

    lol. Opps I guess I forgot to remove the first del

Posting Permissions

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



Click Here to Expand Forum to Full Width