VB Runtime error 3159

D

David

I have a combo box that when selected pulls up records in another
table. It's worked flawlessly in Access 2003-2007. But in Access
2010 I get the 3159 error, and a notice that a bookmark is invalid.

Here's the code in the debugger

Private Sub Combo20_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[Lname] = '" & Me![Combo20] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

This is the code the debuugger highlights:
Me.Bookmark = rs.Bookmark

Any thoughts?

Thanks in advance
 
D

Dirk Goldgar

David said:
I have a combo box that when selected pulls up records in another
table. It's worked flawlessly in Access 2003-2007. But in Access
2010 I get the 3159 error, and a notice that a bookmark is invalid.

Here's the code in the debugger

Private Sub Combo20_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[Lname] = '" & Me![Combo20] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

This is the code the debuugger highlights:
Me.Bookmark = rs.Bookmark

Any thoughts?


Change this line of code:
If Not rs.EOF Then Me.Bookmark = rs.Bookmark

to this:

If Not rs.NoMatch Then Me.Bookmark = rs.Bookmark

.... and see if you get the same error. Maybe you will, maybe you won't, but
that will eliminate one possibility.

Although the code you posted may have been written by Access combo box
wizard, it's still wrong, and always has been. If the record isn't found,
the recordset's .NoMatch property is set, not its .EOF property. So as the
code was, if the record was not found, the code would try to use the
recordset's Bookmark property anyway. Maybe that's what's going on.
 
D

David

Dirk: I made this change, but the error is unchanged.

The combo box wizard did write the original code.
Anything else?

db



I have a combo box that when selected pulls up records in another
table.  It's worked flawlessly in Access 2003-2007.  But in Access
2010  I get the 3159 error, and a notice that a bookmark is invalid.
Here's the code in the debugger
Private Sub Combo20_AfterUpdate()
   ' Find the record that matches the control.
   Dim rs As Object
   Set rs = Me.Recordset.Clone
   rs.FindFirst "[Lname] = '" & Me![Combo20] & "'"
   If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub
This is the code the debuugger highlights:
Me.Bookmark = rs.Bookmark
Any thoughts?

Change this line of code:
   If Not rs.EOF Then Me.Bookmark = rs.Bookmark

to this:

    If Not rs.NoMatch Then Me.Bookmark = rs.Bookmark

... and see if you get the same error.  Maybe you will, maybe you won't, but
that will eliminate one possibility.

Although the code you posted may have been written by Access combo box
wizard, it's still wrong, and always has been.  If the record isn't found,
the recordset's .NoMatch property is set, not its .EOF property.  So asthe
code was, if the record was not found, the code would try to use the
recordset's Bookmark property anyway.  Maybe that's what's going on.

--
Dirk Goldgar, MS Access MVP
Access tips:www.datagnostics.com/tips.html

(please reply to the newsgroup)
 
D

Dirk Goldgar

in message
Dirk: I made this change, but the error is unchanged.
Drat.

The combo box wizard did write the original code.
Anything else?

Well, you can simplify the code a whole lot more, and see if that makes the
error go away. This all by itself ought to work:

'------ start of suggested code ------
Private Sub Combo20_AfterUpdate()

Me.Recordset.FindFirst "[Lname] = '" & Me![Combo20] & "'"

End Sub
'------ end of suggested code ------

That is, provided that the string you're looking for doesn't contain the
single-quote/apostrophe character ('). That code would raise an error if
you tried to find the name O'Malley. You aren't looking for such a name
when it fails, are you?
 
D

David

in message

Dirk:  I made this change, but the error is unchanged.
Drat.

The combo box wizard did write the original code.
Anything else?

Well, you can simplify the code a whole lot more, and see if that makes the
error go away.  This all by itself ought to work:

'------ start of suggested code ------
Private Sub Combo20_AfterUpdate()

    Me.Recordset.FindFirst "[Lname] = '" & Me![Combo20] & "'"

End Sub
'------ end of suggested code ------

That is, provided that the string you're looking for doesn't contain the
single-quote/apostrophe character (').  That code would raise an error if
you tried to find the name O'Malley.  You aren't looking for such a name
when it fails, are you?

--
Dirk Goldgar, MS Access MVP
Access tips:www.datagnostics.com/tips.html

(please reply to the newsgroup)

That takes away the error, but also removed all the functionality.
The dropdown previously populated a subform, but now it doesn't. I
can only assume thje bookmark functionality was being referred to to
do that.

Any other ideas?
 
D

Dirk Goldgar

David said:
Well, you can simplify the code a whole lot more, and see if that makes
the
error go away. This all by itself ought to work:

'------ start of suggested code ------
Private Sub Combo20_AfterUpdate()

Me.Recordset.FindFirst "[Lname] = '" & Me![Combo20] & "'"

End Sub
'------ end of suggested code ------

That takes away the error, but also removed all the functionality.
The dropdown previously populated a subform, but now it doesn't. I
can only assume thje bookmark functionality was being referred to to
do that.


That doesn't make any sense at all. Population of a subform doesn't depend
on the bookmark property in any way. We need to step back and see what else
is going on.

When you say the functionality has been removed, do you mean that the form
doesn't find the record?

What are these properties of the combo box:

Row Source?
Column Count?
Bound Column?
Column Widths?

What is this subform you mentioned? What are its Link Master Fields and
Link Child Fields properties?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top