[AccessD] Odd Error - Embarrassing Workaround

Rocky Smolin rockysmolin at bchacc.com
Tue Nov 28 10:24:20 CST 2017


Dear Lists:

 

In the code below which is in the after update event of a combo box, I want
to position the form to the selected vendor in the combo box list.  Cookie
cutter.  Done it a hundred times:

 

Private Sub cboVendors_AfterUpdate()

 

    If IsNull(cboVendors) Then Exit Sub

    

    lngID = Val(Me.cboVendors.Column(0))

    Set rsMe = Me.RecordsetClone

    

    rsMe.FindFirst "fldVendorID= " & lngID

    If rsMe.NoMatch = True Then

        MsgBox "Record Not Found", vbExclamation

    Else

        Me.Bookmark = rsMe.Bookmark

    End If

    

    Me.cmdExit.SetFocus

    Me.cboVendors.Visible = False

 

End sub

 

The code's a little more wordy than it needs to be because I've been trying
various fixes which, while they shouldn't work, often do in Access. J

 

It blows up on Me.Bookmark = rsMe.Bookmark with an error 2001: You canceled
the previous operation.

 

So here's the odd thing: if I click Debug and see that line highlighted,
then click F5, the code carries on and displays the selected record.

 

I've got a workaround that's so esthetically and professionally offensive
that I hesitate to show it here, but we're all friends, right?

 

Private Sub cboVendors_AfterUpdate()

 

    If IsNull(cboVendors) Then Exit Sub

    

    lngID = Val(Me.cboVendors.Column(0))

    Set rsMe = Me.RecordsetClone

    

    rsMe.FindFirst "fldVendorID= " & lngID

    If rsMe.NoMatch = True Then

        MsgBox "Record Not Found", vbExclamation

    Else

        On Error Resume Next

        Me.Bookmark = rsMe.Bookmark

        Me.Bookmark = rsMe.Bookmark

        On Error GoTo 0

    End If

    

    Me.cmdExit.SetFocus

   Me.cboVendors.Visible = False

 

End Sub

 

All I did was add the On Error line and issue the Bookmark a second time.
The second line apparently works. 

 

Can anyone help me avoid the embarrassment of having to explain to the next
programmer on this app why that code is there? Does anyone know what the
problem is and perhaps a fix?

 

I already tried recompile.  And also ran it through the decorrupter.

 

MTIA

 

 

Rocky Smolin (semi-ret.)

Beach Access Software

760-683-5777

 <http://www.bchacc.com> www.bchacc.com

 <http://www.e-z-mrp.com> www.e-z-mrp.com

Skype: rocky.smolin

 

 



More information about the AccessD mailing list