Results 1 to 18 of 18

Thread: :lol: (my delte record code adds a record)

  1. #1

    Thread Starter
    Fanatic Member cid's Avatar
    Join Date
    Nov 2002
    Location
    Fort Worth, Texas
    Posts
    854

    :lol: (my delte record code adds a record)

    VB Code:
    1. On Error Resume Next 'Err handling
    2. ADOCn.BeginTrans
    3. 'setup your rs here
    4. ADOCn.Execute "DELETE FROM Permits WHERE [Tract_ID] = " & Combo1.SelText
    5. If Err.Number <> 0 Then
    6.     ADOCn.Rollback
    7. Else
    8.     ADOCn.Execute "DELETE FROM Permitsw WHERE [Tract_ID] = " & Combo1.SelText
    9.     If Err.Number <> 0 Then
    10.         ADOCn.Rollback
    11.     Else
    12.         ADOCn.CommitTrans
    13.     End If
    14. End If
    15. rsvalues.Update
    16. rsvalues.moveprevious
    17. On Error GoTo 0

    So basically I want it to delete the record that is tied to the field "Tract_ID" And a user selects which record out of the field from a combobox....

    BUT ITS ADDING A BLANK NEW FIELD

    www.google.com - Pay Tribute.

    Always Listening To: Thrice

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: :lol: (my delte record code adds a record)

    There is no need for "rsvalues.Update", as you have not modifed rsvalues at all. The fact that this is adding a new record probably means that somewhere earlier you ran "rsvalues.Addnew", but didn't run an update with it (you should find this and fix it!).

    For this code however, you should run an "rsvalues.ReQuery" to get the recordset up to date with your changes.

    I don't understand why you have "rsvalues.moveprevious" there either.

  3. #3
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: :lol: (my delte record code adds a record)

    cid,

    Also if a delete does not work there is nothing to rollback... Transactions are worthless in this case. At least for the first delete.

  4. #4
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: :lol: (my delte record code adds a record)

    cid,

    A better way to do this would probably be this:

    VB Code:
    1. On Error Resume Next 'Err handling
    2. ADOCn.BeginTrans
    3. 'setup your rs here
    4. ADOCn.Execute "DELETE FROM Permits WHERE [Tract_ID] = " & Combo1.SelText, RecordsAffected
    5. if RecordsAffected > 0 then ADOCn.Execute "DELETE FROM Permitsw WHERE [Tract_ID] = " & Combo1.SelText, RecordsAffected
    6.  
    7. If RecordsAffected = 0 then
    8.    ADOCn.RollbackTrans
    9. else
    10.    ADOCn.CommitTrans
    11. End If

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: :lol: (my delte record code adds a record)

    I think it should be kept - the way it is at the moment, if the second delete fails then the first will be rolled back.

    Rolling back the first seem to be worthless, but it cancels the transaction.


    edit: nice alternative method you just posted!

  6. #6

    Thread Starter
    Fanatic Member cid's Avatar
    Join Date
    Nov 2002
    Location
    Fort Worth, Texas
    Posts
    854

    Re: :lol: (my delte record code adds a record)

    Thank you Randem, But before I worship you.... What should i dim RecordsAffected as?

    It says variable not defined

    www.google.com - Pay Tribute.

    Always Listening To: Thrice

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: :lol: (my delte record code adds a record)

    It should be ADOCn.RecordsAffected

  8. #8
    Frenzied Member SeanK's Avatar
    Join Date
    May 2002
    Location
    Boston MA
    Posts
    1,160

    Re: :lol: (my delte record code adds a record)

    Quote Originally Posted by cid
    Thank you Randem, But before I worship you.... What should i dim RecordsAffected as?

    It says variable not defined
    What are you using it for? The answer to that will tell you what is should be created as.
    Beantown Boy
    Please use [highlight=vb]your code goes in here[/highlight] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.

  9. #9

    Thread Starter
    Fanatic Member cid's Avatar
    Join Date
    Nov 2002
    Location
    Fort Worth, Texas
    Posts
    854

    Re: :lol: (my delte record code adds a record)

    Actually, what does recordsaffected do?

    Dim ADOCn as ADODB.Connection

    There is no "ADOCn.RecordsAffected"?

    www.google.com - Pay Tribute.

    Always Listening To: Thrice

  10. #10
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: :lol: (my delte record code adds a record)

    It is a property of the connection object, which tells you how many records were affected by the last Execute (in this case: how many records were deleted). It does not need to be defined.

    Just change "RecordsAffected" in randems code to "ADOCn.RecordsAffected"

  11. #11

    Thread Starter
    Fanatic Member cid's Avatar
    Join Date
    Nov 2002
    Location
    Fort Worth, Texas
    Posts
    854

    Re: :lol: (my delte record code adds a record)

    Thank you for the help... although my ADOCn. doesnt recognize a command in there called RecordsAffected...

    here is the commands before and after where it is supposed to be:

    ADOCn.Provider

    ADOCn.RollbackTrans

    www.google.com - Pay Tribute.

    Always Listening To: Thrice

  12. #12
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: :lol: (my delte record code adds a record)

    FYI: RecordsAffected is NOT ADO it is DAO
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  13. #13

    Thread Starter
    Fanatic Member cid's Avatar
    Join Date
    Nov 2002
    Location
    Fort Worth, Texas
    Posts
    854

    Re: :lol: (my delte record code adds a record)

    Quote Originally Posted by Static
    FYI: RecordsAffected is NOT ADO it is DAO
    This is no good, I am using ADO not DAO

    www.google.com - Pay Tribute.

    Always Listening To: Thrice

  14. #14
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: :lol: (my delte record code adds a record)

    cid,

    RecordsAffected is defined as a long.

    More info ADO .Execute
    Last edited by randem; Nov 4th, 2005 at 02:16 PM.

  15. #15

    Thread Starter
    Fanatic Member cid's Avatar
    Join Date
    Nov 2002
    Location
    Fort Worth, Texas
    Posts
    854

    Re: :lol: (my delte record code adds a record)



    I cant add new records, and i cant delete them... what is going on?

    When I goto delete a record all it does is just sit there... but when i hit rsvalues.moveprevious it says EOF ( record has been deleted)... but when i open the database back up, the record is still there....

    Its like it isnt refreshing properly but i have my requery outside of my loop, and i defined records affected as long...

    any ideas?

    thanks randem for the link

    www.google.com - Pay Tribute.

    Always Listening To: Thrice

  16. #16
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: :lol: (my delte record code adds a record)

    Could you post your project? It seems your issues stem from somewhere else.

  17. #17

    Thread Starter
    Fanatic Member cid's Avatar
    Join Date
    Nov 2002
    Location
    Fort Worth, Texas
    Posts
    854

    Re: :lol: (my delte record code adds a record)

    acutally no, the project is about 3 megs... with the dlls, forms, database, and ocx's

    pm me your email and i will be more than happy to send it to you

    www.google.com - Pay Tribute.

    Always Listening To: Thrice

  18. #18
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: :lol: (my delte record code adds a record)

    part of it (with my comments on the issues) is here:
    http://www.vbforums.com/showthread.p...38#post2230538

    FYI: RecordsAffected is NOT ADO it is DAO

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