UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Selecting A Record In Ado Recordset, Access 2013    
 
   
SomekindaVB
post Nov 13 2017, 07:08 PM
Post#1



Posts: 154
Joined: 15-December 16



Hi All.

I am trying to allow for a user to delete a record in an ado recordset on a subform

So far I have this

CODE
Dim rsADORecord As ADODB.Recordset
Dim lngrecordNumber As Long
Dim strCriteria As String
    
    DoCmd.Hourglass True
    LockWindowUpdate Me.Parent.hwnd
    Set rsADORecord = Me.Form.Recordset
    With rsADORecord
        
        lngrecordNumber = ![record Number]
        .Delete adAffectCurrent
        'Attempts to resolve a eof or bof error.  acts a bit odd but
        Me.TxtFocus.Enabled = True: Me.TxtFocus.Locked = False: Me.TxtFocus.SetFocus
        Me.TxtFocus.Enabled = False: Me.TxtFocus.Locked = True
        .MoveNext
        lngrecordNumber = ![record Number]
    
        If IsNull(![record Number]) Then Exit Sub
        strCriteria = "[Record Number]=" & lngrecordNumber

        'rsADORecord.Find strCriteria
        rsADORecord.Bookmark = rsADORecord.Clone.Bookmark '<- The problem
      
    End With
    Set rsADORecord = Nothing


The problem is the selected record always ends up being the first record, and not the One I want. Maybe I got confused with the clone part of this, but I don't really know.

Can anyone advise how to find the next record after deleting one.

Cheers
Go to the top of the page
 
cheekybuddha
post Nov 14 2017, 06:02 AM
Post#2


UtterAccess VIP
Posts: 9,275
Joined: 6-December 03
From: Telegraph Hill


Hmmm ...

Surely just moving to the next record will put the recordset on the next record or .EOF. No need to bother with the recordset.Clone

What happens if you try simply:
CODE
  With Me.Recordset
    .Delete adAffectCurrent
    .MoveNext
    If .EOF Then .MovePrevious
  End With


hth,

d

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


Regards,

David Marten
Go to the top of the page
 
SomekindaVB
post Nov 15 2017, 04:48 PM
Post#3



Posts: 154
Joined: 15-December 16



Wonderful!

Very simple. I'm sure I wrote hundreds of lines of code to try circumvent this problem, bouncing back and forth between error handling routines, and this works perfectly.

thanks so much!

Cheers
Go to the top of the page
 
cheekybuddha
post Nov 16 2017, 05:59 AM
Post#4


UtterAccess VIP
Posts: 9,275
Joined: 6-December 03
From: Telegraph Hill


yw.gif

I'm glad it worked for you!

You may want to add a test to check you are actually on a record before attempting to delete:
CODE
  With Me.Recordset
    If Not(.BOF Or .EOF) Then
      .Delete adAffectCurrent
      .MoveNext
      If .EOF Then .MovePrevious
    End If
  End With


Continued success with your project! thumbup.gif

d

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


Regards,

David Marten
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    11th December 2017 - 12:11 PM