Results 1 to 4 of 4
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Closing Recordsets Left Hanging Open (2003)

    In the Click event for the Comando50 button on the startup form of the attached mdb, I'm trying to use the line
    <font color=red>If rst.State = adStateOpen Then rst.Close</font color=red>
    but I get the
    <font color=448800>Ado runtime error 3219: The operation requested by the application is not allowed in this context. .</font color=448800>
    when the code executes that line.
    How do you then close recordsets left open?
    (The rst recordset is left open if I try inserting a date that's already present)

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Closing Recordsets Left Hanging Open (2003)

    I would declare cnn and rst locally, within the procedure.
    To prevent rst remaining open, close in in the exit handler section of Comando50_Click:

    ...

    Exit_Command191_Click:
    On Error Resume Next
    rst.Close
    Set rst = Nothing
    Set cnn = Nothing
    Exit Sub

    Err_Commmand191_Click:
    ...

    (Very strange naming convention, by the way)

    You can remove the line If rst.State = adStateOpen Then rst.Close.

  3. #3
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Closing Recordsets Left Hanging Open (2003)

    Thank you Hans
    <hr>(Very strange naming convention, by the way)<hr>
    I copied and adapted the code from another button and forgot to change the references to the current button. <img src=/S/blush.gif border=0 alt=blush width=15 height=15>

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Closing Recordsets Left Hanging Open (2003)

    I always use the generic names ExitHandler and ErrHandler; that way I can copy code from one procedure to another without having to modify the labels.

Posting Permissions

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