?
Solved

Main Form Requery and Set Bookmark Generates error 2001

Posted on 2006-05-31
4
Medium Priority
?
536 Views
Last Modified: 2007-12-19
When I update a field in a subform I want to recalculate the associated values in the main form while maintaining the bookmark at the current row. The subroutine below generates an error 2001. I do not see what is wrong with the code.


Public Sub Requery_SalesHeader()
 
Me.Parent.Requery
Dim rs As ADODB.Recordset
Set rs = Me.Parent.RecordsetClone
rs.Find "[Sales docu]=" & Me.[Sales docu] ' find the row in the main form that matches the current subform row.

If rs.RecordCount > rs.Bookmark Then
  Me.Parent.Bookmark = rs.Bookmark + 1               ' error generated here
End If
Me.Parent.Bookmark = rs.Bookmark
 
End Sub
0
Comment
Question by:guilloryt
  • 2
  • 2
4 Comments
 

Author Comment

by:guilloryt
ID: 16801910
The error appears to occur only when I am set a filter on the main form.

 Forms![frmSalesHeader].FilTer = strSql
  Forms![frmSalesHeader].FilterOn = True
0
 
LVL 58

Expert Comment

by:harfang
ID: 16804435
Hello guilloryt

There are several problems with your code sample:
 • you use .Find on rs, but never check or  use the result
 • you compare the total number of records with a bookmark
 • you attempt to calculate with a bookmark

A bookmark is not a number. It's a string expression used to identify a record within a given recordset, but it has nothing to do with a record number.

I believe you will have to invent another logic for what you need to do.

Cheers!
(°v°)
0
 

Author Comment

by:guilloryt
ID: 16806392
Thats odd. It works as long as I do not have an active formfilter. It allows the user to update the data in a subform field. In the after update event on that subform field the requery sales header forces the parent form to requery and then point the parent forms bookmart to the primary key that is selected in the subform. If it is not the last record then the main form moves to +1 past the desired row and back one. The reason for this is it allows both the parent form and subform to be open in datasheet and allow viewing of the all the data. Otherwise some of the subform datasheet rows may scroll off the screen.
0
 
LVL 58

Accepted Solution

by:
harfang earned 2000 total points
ID: 16812584
Hello guilloryt

I understand now. You are using an ADO recordset (I should have seen that), and under certain circumstances, Jet will use a double value as bookmark. Also, this value is sometimes identical with the absolute position of the record, so that you used it as a substitute for the .AbsolutePosition property.

Your code does in fact this:

If rs.RecordCount > rs.AbsolutePosition Then
  Me.Parent.Recordset.AbsolutePosition = rs.AbsolutePosition + 1
End If
Me.Parent.Recordset.AbsolutePosition = rs.AbsolutePosition

A Bookmark, however, is used for mainly one thing: storing a position in a recordset and returning to that position. Using ADO, this is no longer a string, but a Variant. However (from ADO help):

The user may not be able to view the value of the bookmark. Also, users should not expect bookmarks to be directly comparable—two bookmarks that refer to the same record may have different values.

ADO introduces some new methods using bookmarks, like the CompareBookmark method. But bookmarks are still something different from record positions.


Going back to your code, you can solve the scrolling issue in a different way:

Me.Parent.Bookmark = rs.Bookmark
DoCmd.GoToRecord acDataForm, Me.Parent.Form.Name, acNext
DoCmd.GoToRecord acDataForm, Me.Parent.Form.Name, acPrevious

This assumes that there is a "blank" record to go to. If not, you would have to test that as before.

Hope this helps!
(°v°)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question