Results 1 to 6 of 6
  1. #1
    swalsh84 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jan 2010
    Posts
    36

    OStream Delete Last Record

    I have an ostream recordset that is having a bear of a time doing something simple. I have a main recordset plus a detail recordset. When attempting to delete a detail record, I have tried just about everything.

    I had a SP running to delete the detail record, but when you try to reload, there are connection conflicts and the application stalls and has to force quit. When you use the built in Access macros, the first and middle records can be deleted as well as the last, but when you try to delete the first or middle record then skip to the last, it nulls the fields and leaves the last record there, undeleted.

    I've narrowed down the problem to this: for each record in a streaming recordset, a bookmark is assigned but unchanged when the number of records in the recordset changes. If you delete the first, the bookmarks for all of the other records remain the same. This poses a problem because you can never compare the last records bookmark value to the record count. I've determined that one has to write different code for each case, but the last record will still not delete. See code below so that this hopefully makes more sense.


    Code:
    Public Sub DeleteDetail()
        If Not bDev Then On Error GoTo PROC_ERR
        PushCallStack ("mdlMain - DeleteDetail")
        Dim sBookMark As String
        Dim rsClone As ADODB.Recordset
        Dim delLDID As Long
        
        Form_fsubLossTypeDetail.Refresh
        Set rsClone = Form_fsubLossTypeDetail.RecordsetClone
        delLDID = gLossDetailID
        Debug.Print rsClone.Bookmark
        Debug.Print rsClone.AbsolutePosition
        Debug.Print rsClone.RecordCount
        
        With rsClone
            If .AbsolutePosition = .RecordCount - 1 Then
                rsClone.MoveFirst
                Do While Not rsClone.EOF
                    If rsClone!LossDetail_ID = delLDID Then
                        sBookMark = rsClone.AbsolutePosition
                        rsClone.Delete
                    End If
                    rsClone.MoveNext
                Loop
                
                If sBookMark > 1 Then
                    Form_fsubLossTypeDetail.Bookmark = sBookMark - 1
                Else
                    Form_fsubLossTypeDetail.Bookmark = sBookMark
                    Set rsClone = Form_fsubLossTypeDetail.RecordsetClone
                End If
            Else
                DoCmd.RunCommand acCmdDeleteRecord
    '            Form_fsubLossTypeDetail.Refresh
            End If
        End With
        
    PROC_EXIT:
        Set rsClone = Nothing
        'rsClone.Close
        PopCallStack
        Exit Sub
    PROC_ERR:
        GlobalErrHandler Err.Number, Err.Description, True, gCLATrackID, Erl
        Resume PROC_EXIT
    End Sub
    I'm not sure how to make this happen. I'm open to suggestions. Thanks.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,896
    Try setting rsClone = Nothing before Setting it again in the Else. On second thought, that doesn't seem necessary.

    Want to provide project for analysis?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    swalsh84 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jan 2010
    Posts
    36
    No luck on setting the rs to nothing.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,896
    Am wondering why using RecordsetClone. If you have the ID as criteria for records that need to be deleted, why not just a DELETE sql?

    Again, do you want to provide project for analysis?

    What is 'ostream'?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    swalsh84 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jan 2010
    Posts
    36
    I can't post as it's a proprietary project and won't work if you had it any way. The access file is just a GUI for a SQL server app because IT won't let me have VS.

    I'm using recordsetclone because the form recordset is not accessible when you are using a streaming recordset via ostream. This is the code used to create a streaming record set. What changes in the form, changes on the SQL server.

    Code:
    Public Function Clone(ByVal oRs As ADODB.Recordset, Optional ByVal LockType As ADODB.LockTypeEnum = adLockUnspecified) As ADODB.Recordset
        If Not bDev Then On Error GoTo PROC_ERR
        PushCallStack ("mdlFunctions - Clone")
        
        Dim oStream As ADODB.Stream
        Dim oRsClone As ADODB.Recordset
        
        'save the recordset to the stream object
        Set oStream = New ADODB.Stream
        oRs.Save oStream
        
        'and now open the stream object into a new recordset
        Set oRsClone = New ADODB.Recordset
        oRsClone.Open oStream, , , LockType
        
        'return the cloned recordset
        Set Clone = oRsClone
        
        'release the reference
        Set oRsClone = Nothing
        
    PROC_EXIT:
        PopCallStack
        Exit Function
    PROC_ERR:
        GlobalErrHandler Err.Number, Err.Description, True, gCLATrackID, Erl
        Resume PROC_EXIT
    The original method was to use a stored procedure to delete the record in question. The procedure didn't fail, but when a different procedure that loads up the streaming recordset tried to run, it locked itself up even after trying to kill the connection and rekindle it.

    I resorted to using the Access built in macros to delete and that's when I discover the last record issue above.
    Last edited by swalsh84; 05-15-2012 at 11:43 AM. Reason: unanswered question.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,896
    Sorry, this is beyond my experience.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Trying to Delete record using delete query
    By MooseOTL in forum Access
    Replies: 13
    Last Post: 10-04-2011, 02:30 AM
  2. Delete Record; Yes/No
    By mar_t in forum Access
    Replies: 5
    Last Post: 03-10-2011, 07:15 AM
  3. Delete record if duplicate
    By rubintheyid in forum Access
    Replies: 8
    Last Post: 03-30-2010, 11:33 AM
  4. Delete record harder than it seems
    By turbo910 in forum Forms
    Replies: 5
    Last Post: 12-09-2009, 04:05 PM
  5. Delete a record
    By f.crocco in forum Programming
    Replies: 1
    Last Post: 10-08-2007, 07:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums