Results 1 to 18 of 18

Thread: delete recorset is driving me crazy

  1. #1

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Angry

    HELP PLEASE!

    Code:
        Do While Not Rs.EOF
            Rs.Delete
            Rs.MoveNext
        Loop
    I am calling the above from Excel, rs is my imaginatively named variable for a recordset.

    All I would like to do is delete everything from a recordset when Excel closes (keeping column headers etc, would prefer not to create table each time Excel page starts). Can anyone point me in the right direction here please?

    Thank you! this is GREATLY appriciated as this is just starting to get to me...
    Alex read

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  2. #2
    Lively Member
    Join Date
    Feb 1999
    Location
    Leicester, UK
    Posts
    123
    Is your starting point the beginning of the recordset?

    Do you need rs.movefirst before your loop?

  3. #3

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Post But ...

    Thank you for responding Michael, unfortunatley I tried this one & it hasn't worked, I have also been trying:

    Code:
    for i = 1 to rs.recordcount
    Do While Not Rs.EOF
            rs.movefirst
            Rs.Delete
            Rs.MoveNext
        Loop
    next i
    incase that helped, but nothing yet, is there anything else wrong with the above ?

    Thank you,
    Alex Read

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  4. #4
    Lively Member
    Join Date
    Feb 1999
    Location
    Leicester, UK
    Posts
    123
    I would stick with your original code - with rs.movefirst before the loop (outside it).

    Your latest code should work but the extra lines serve no useful purpose and only help to confuse the issue.

    It's not a read-only recordset is it?

  5. #5

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Thumbs up how stupid am I ...

    Thank you once again Michael, god I love this forum!
    You were right, I had placed the rs.movenext in the wrong place!

    Thank you,
    Alex

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  6. #6
    Lively Member
    Join Date
    Feb 1999
    Location
    Leicester, UK
    Posts
    123
    You're welcome.

    I would say something like "what a silly-billy" if I hadn't done any stupid things myself!!! But I won't!!!

  7. #7
    Fanatic Member
    Join Date
    Jul 2000
    Location
    Manchester NH
    Posts
    833

    "select * from cars where prodnum < 183"

    rs.movefirst
    do until rs.eof
    rs.delete
    rs.movenext
    loop


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

    or with SQL

    "delete * from cars where prodnum < 183"



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

    same result
    Kurt Simons
    [I know I'm a hack but my clients don't!]

  8. #8
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    Wink

    Syntax error (Sorry to sound like a *****)

    "delete * from cars where prodnum < 183"

    should be

    "delete from cars where prodnum < 183"

    Without the Star! I often mistype that myself so all is forgiven
    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  9. #9
    Fanatic Member
    Join Date
    Jul 2000
    Location
    Manchester NH
    Posts
    833
    sorry, wrote it quick

    its the concept that counts!
    Kurt Simons
    [I know I'm a hack but my clients don't!]

  10. #10
    Lively Member
    Join Date
    Feb 1999
    Location
    Leicester, UK
    Posts
    123
    Paul is right - SQL is far superior.

    However, I also know how annoying it is when you can't get what should be a simple piece of code to work. Been there - Done that - Got the T-shirt!!!

  11. #11

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Talking

    I'd definitley agree with that one Michael, I too have been there, didn't get the t-shirt mind...

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  12. #12
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    i hate databases, they are a pain!!!!

  13. #13

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    da_silvy,

    Can you think of a VB app without a database? 15,000 registry entries to access or putting all the info in a text file? AAARRRGGGHHHH!

    I guess they do serve a useful purpose, but coding with them can be ridiculous sometimes (my one I should have spotted here but...)

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  14. #14
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    I think they only get annoying when everything has to be split into half a million text boxes for a user...

    As far as data retrieval and manipulation goes I think they're great. I usually chuck the relevant data to an array or UDT right at the start and work from there. Although just connecting a front end can be pretty tedious.
    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  15. #15

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Paul, think of a vb learning edition, then think of NO visdata (whatever it's called), then think of NO tools to help databases communicate with VB forms, but rather everything drawn & connected manually (the data control works for very simple parts).

    Ok, now think of computer out the window, then of men in white coats....

    From your signature I take it you don't have the learning ed,

    I feel musically inspired here:
    "wouldn't it be good to be in your shoes" !

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  16. #16
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    Close, but no cigar!

    I learned DB from ASP connecting to SQL server with ADO(and SQL server admin)

    Then found in VB that if you reference the ADO (forget the activeX controls) it's all the same code but with real data types. Use SQL syntax strings to do the work rather than screwing around with the finer points of the RS.

    I bought the "DB Programming with VB 6" book which is great but I haven't read as much of if as I would like, I like just staying with the SQL.

    No tool, not data aware controls, just a home made text editor for ASP (which I left at my last company and lost the source )
    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  17. #17

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Ok, will shut up now .....

    wowsers , & I though I had it bad to most of you! I am learning ADO now comming from DAO, and use the basics of SQL mixed in when I cannot find the DAO code to do the same thing, but that is ridiculous.

    I can't compete with that one, not sure how anyone could do a job like that either

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  18. #18
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    they may be useful, but i still don't like coding them!

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