473,883 Members | 1,687 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

recordset.bookm ark problem

Seth Schrock
2,965 Recognized Expert Specialist
I have the following subroutine that I'm using to bookmark the current record, do a requery of the form, and then go back to the record that I bookmarked. Here is my code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub FormRefresh()
  2. Dim varBookmark As Variant
  4. With Me.sfrmCrimes.Form
  5.     varBookmark = .Recordset.Bookmark
  6.     .Requery
  7.     If IsEmpty(varBookmark) Then
  8.         MsgBox "Bookmark is empty"
  9.     Else
  10.         .Recordset.Bookmark = varBookmark
  11.     End If
  12. End With
  14. End Sub
When it runs, it stops on line #10 and says
Run-time error '3129':
Not a valid bookmark.

If I select "Debug", line #10 is highlighted. If I then drag it up to line #7 and then step through the code using F8, then the code runs fine. This defies all troubleshooting methods that I have ever heard of, so I have no idea how to test this. I initially put in the If/Then statement to test varBookmark as I wanted to see if it wasn't getting passed the bookmark for some reason. However, I never get the "Bookmark is empty" message. What am I doing wrong?

This is the first time that I have ever used the Recordset.Bookm ark property. Here is the link that I was trying to follow when I created this: MSDN Recordset.Bookm ark Property
Dec 29 '12 #1
12 16084
2,322 Recognized Expert Moderator Top Contributor
If you read the link you posted:
MSDN However, you can't use bookmarks from different Recordset objects interchangeably , even if they were created by using the same object or the same SQL statement.
Consider the bookmark as you would a "real" life bookmark, and the recordset as you would a real life book. Now when you open a recordset its like buying a book. You can place a bookmark in the book (recordset) and return to the bookmark later. But opening a new recordset is like getting a new book. Opening a new recordset with the same sql (Such as when you requery) is like getting a new copy of the same book. Problem is you can't use the bookmark, cause its stuck in the old/first book.

So in short, you cannot use the bookmark in that way. If the records have a unique ID (And they should!!!!) then you can use that instead. Lets assume your primary key for the record is simply called PK_Record and is numeric.

Expand|Select|Wrap|Line Numbers
  1. Private Sub FormRefresh()
  2. dim lngRecordID as long
  4. With Me.sfrmCrimes.Form
  5.     lngRecordID = .lngRecordID
  6.     .Requery 
  7.     .RecordSet.FindFirst "lngRecordID=" & lngRecordID 
  9. End With
  11. End Sub
That is the simplest version of the code, to get more advanced you could add in checks for whether the record is found (what if another user deleted it in the meantime?), or what if you start by standing on a empty(new) record?, however I can't advice on this since the details are missing.
Dec 29 '12 #2
Seth Schrock
2,965 Recognized Expert Specialist
I didn't catch that a requery would fall into the category of being created by using the same object or the same SQL statement. Thank-you for pointing this out.

And your suggestion worked perfectly. The only check I added was to make sure that sfrmCrimes was not on a new record.
Dec 29 '12 #3
2,322 Recognized Expert Moderator Top Contributor
Happy to be of assistance. I remember it as not too long ago I had the same/similar learning experience with using bookmarks. :)

Best of Luck with your project
Dec 29 '12 #4
8,834 Recognized Expert Expert
Your original concept will actually work:
Expand|Select|Wrap|Line Numbers
  1. Dim varBookmark As Variant
  3. With Me.sfrmCrimes.Form
  4.   varBookmark = .Recordset.Bookmark
  6.   'Requery the Sub-Form Control, NOT the underlying Form itself
  7.   Me.sfrmCrimes.Requery
  9.   If IsEmpty(varBookmark) Then
  10.     MsgBox "Bookmark is empty"
  11.   Else
  12.     .Recordset.Bookmark = varBookmark
  13.   End If
  14. End With
Dec 29 '12 #5
Seth Schrock
2,965 Recognized Expert Specialist
Perfect ADezii! I just tried it and I like it much better. I always saw the record jump when using the .Recordset.Find First method and using the bookmark had no jump at all. Thanks so much.
Dec 29 '12 #6
8,834 Recognized Expert Expert
@Seth Schrock
Yopu are quite welcome.
Dec 29 '12 #7
32,584 Recognized Expert Moderator MVP
'Requery the Sub-Form Control, NOT the underlying Form itself
Nice. This question has given me an idea as to how I can improve some code I expect to be working on again shortly.

I'm pretty sure this also means (and I'm highlighting this because it seems important to understand rather than as a criticism of Smiley's attempt to be helpful) that a .Requery() does not cause the Recordset object to be considered to be a separate Recordset from before the .Requery().
Dec 31 '12 #8
Seth Schrock
2,965 Recognized Expert Specialist
What then would be the reason for my initial code to not work? I assumed that this proved that Smiley was correct and that a requery of the control didn't requery the form's recordsource (allowing the bookmark to work) whereas a requery of the form inside the subform control did cause the form's recordsource to be redone (causing the bookmark to fail). As this is the only difference in the two pieces of code, I'm at a loss for what could be the cause of the original to fail if that is not it.
Dec 31 '12 #9
32,584 Recognized Expert Moderator MVP
I'm not sure Seth. I may be wrong - hence the wording of my post. I too, want that to be clarified. I must admit though, that the idea of a .Requery() call meaning that a recordset is no longer the same recordset seems logically quite wrong to me. The recordset is not being recreated. merely requeried/refreshed. Refresh is the term I want to use, but that has a specific meaning with regards to recordsets in Access.

If Smiley is correct, then it's important that point is understood. Whatever the answer, it should really be understood rather than guessed at is my view.
Dec 31 '12 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Dave | last post by:
Hi all, I've been trying to figure this out for the last day and a half and it has me stumped. I've got a web application that I wrote that keeps track of trading cards I own, and I'm moving it from an Access 2000 database to a SQL Server 2000 database. Everything worked perfectly in Access, but I'm having trouble getting data to display in SQL Server. For reference, here's the query. It's big and nasty, but I thought
by: HKM | last post by:
Hello, I have a query engine that builds the SQL Query to obtain the recordSet. Following is an Exmaple Query that my QueryBuilder outputted SELECT * FROM BookInfo WHERE BookName LIKE '*cobol*' When I use this query to build recordset I get empty recordSet back when the BookInfo table has entries that qualify for this criteria. To
by: DrFoo | last post by:
(Access 97 and 2003) Hi, Here's a smippit of code that works correctly about 95% of the time. This part of the algorithm... - find the first value = true - if found, find next value = false - if found, find next value = true
by: corepaul | last post by:
I am fairly new to Access and I have a problem trying to use bookmarks with a recordset. I have a recordset dimensioned as, Dim rstFoodDesc As ADODB.Recordset ' recordset Dim bMark As Variant ' variable to store bookmark I open the recordset with the statements,
by: Wayne Wengert | last post by:
In VB6/ADO I used to use the code below to put all the records that did not have a valid email address into an array which I used later to print mailing labels. I am not aware of a NET equivalent. What is the right way to approach this in NET? Wayne ============================================== varSentToCount = 0 'Count of recipients
by: Tony Rice | last post by:
I"d like to hear critiques on the following method for dealing with the back button and bookmarkability problem with AJAX. Whenever I do something on a page with ajax, I add to document.location.hash (which doesn't reload the page but does include the parameters in a bookmark) like so: document.location.hash = document.location.hash + '&param=value'; So the URL gets updated like so:...
by: Kaur | last post by:
Hi, I am having a strange bookmark problem. I have a main form called frmSurveyQSubQ. This form has a subform called sfrmRespodent. SfrmRespondent has a sfrm in it called sfrsfrmResponses. I have a list box on main form called lstQuestion that displays all the questions relevant to a survey. Clicking on a question in it fills the second list box "lstSuquestion" with relevant sub questions for selected question in lstQuestion on main...
by: Lazster | last post by:
Hi, I'd really appreciate some help here people. I am trying to insert some values in a table in another database and not getting the results I am expecting. I am simply trying to insert values via a connection to a recordset and then close the recordset. However I keep getting a type mismatch on the variable rstMainData. Please can someone help me? The code is as below.
by: fieldling | last post by:
I've written the following code to update a recordset but when I run it I get a Run-time error 3020: Update or CancelUpdate without AddNew or Edit. When I debug it highlights the rs.update line. I've serached this forum and others for an answer but no luck. Anyone got any ideas? Thanks Option Compare Database Public Function fImportdata() Dim db As DAO.Database Dim rs As DAO.Recordset Set db = CurrentDb() Set rs =...
by: nimeshjaiswal | last post by:
Hi, I m doing a migration project from VB6 to VB.NET 2008. I m facing problem in migration the recordsets to dataset specially with properties in fields and bookmark with recordset. Please..Please... provide the solution asap. Thanks in advance. Nimesh
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.