Learn Microsoft Access Advanced Programming Techniques, Tips and Tricks.

Form Recordset and Bookmarks

Introduction.

Bookmarks are stored on individual records of a Recordset, when loaded into memory on a Form.  When a Table or Query linked to a Form is open a unique Id is generated and stored in the Bookmark Property of each record.  When you close the Form this is cleared.  Bookmarks are a two Byte data of String Type.  They are not displayable or printable characters, when printed on screen it simply displays a ? character.

Not all Recordsets have Bookmarks and this can be checked by reading it’s  Bookmarkable Property Value.  If the Bookmarkable Property value is false then this Recordset doesn’t have bookmarks.

If you create a Recordsetclone in VBA from a Form’s (say Form-A) Recordset the Recordsetclone’s bookmark and Form’s Recordset bookmarks will be identical. You can use the StrComp() Function to compare Bookmarks.  Use 0 (zero) as third argument of the function.

But, if you load the same Table on a different Form (say Form-B) at the same time both form’s Recordset bookmarks will not be identical.  When you close and open the Form with same table a second time both session’s bookmarks of records will not be identical.

When an attached Table having no Primary Key is open in a Form that Recordset will not have any bookmarks.

When Form doesn’t have a Record Source Value then addressing Form’s Bookmark Property will trigger an error.  But, when a Table or Query is loaded into the Record Source property of the Form, the Form will have a Bookmark Property only for the Current Record.  You can move the records on the Form and read their bookmarks and save them into different Variables to come back to those records later through VBA.


Sample Bookmrk Based Trial Run.

Let us try a simple example to save the Bookmark of a record on the Form into a variable and use it later to come back to the bookmarked record.

  1. Import the Employees Table from Norwind sample database.
  2. Create a Tabular Form for Employees Table.
  3. On the Footer Section of the Form create two Command Buttons.
  4. Select the first Command Button.
  5. Display it’s Property Sheet (F4).
  6. Change the Name Property value to cmdSave. 
  7. Change the Name Property value of the second Command Button to cmdRestore.
  8. Display the VBA Module of the Employees Form.
  9. Copy and Paste the following Code into the VBA Module:
    Dim bkMark As Variant
    
    Private Sub cmdRestore_Click()
       Me.Bookmark = bkMark
       MsgBox "Bookmark Restored"
    End Sub
    
    Private Sub cmdSave_Click()
        bkMark = Me.Bookmark
        MsgBox "Bookmark saved" 
    End Sub
    
    
  10. Save and Close the Form.
  11. Open the Form in normal view showing employee records.
  12. Use the record navigation control to move to the 5th record.
  13. Click on the Save Command button to save the Bookmark of the current record in bkMark Variable.
  14. Now, move few records forward on the Form.
  15. Click on the Restore Command Button to quickly make the 5th record current on the Form, by copying the Bookmark from bkMark Variable into the Form’s Bookmark Property.  You can try this out with different records on the Form.

The following Links will show you more tricks on this topic with interesting examples:

  1. Form Bookmarks and Data Editing
  2. Form Bookmarks and Data Editing-2
  3. Form Bookmarks and Data Editing-3
  4. Forms and Custom Properties
  5. Saving Data on Forms not in Table
Share:

No comments:

Post a Comment

Comments subject to moderation before publishing.

MS-Access Tips on your Finger-Tip

  • Download Android App 'MSA Guru' Version of LEARN MS-ACCESS TIPS AND TRICKS from Google Play Store.

Want to Post Free Ads on the Web


Translate



PageRank
Subscribe in a reader
Your email address:

Delivered by FeedBurner

Search

Popular Posts

Blog Archive

Powered by Blogger.

Follow by Email

Labels

Forms Functions How Tos MS-Access Security Reports msaccess forms Animations msaccess animation Utilities msaccess controls Access and Internet MS-Access Scurity MS-Access and Internet Class Module External Links Queries Array msaccess reports Accesstips WithEvents msaccess tips Downloads Menus and Toolbars Objects Collection Object MsaccessLinks Process Controls Art Work Property msaccess How Tos Dictionary Object Graph Charts Query VBA msaccessQuery Calculation Combo Boxes Event List Boxes Command Buttons Controls Data Emails and Alerts Form Custom Functions Custom Wizards DOS Commands Data Type Key Object Reference TreeView Control ms-access functions msaccess functions msaccess graphs msaccess reporttricks Command Button Report msaccess menus msaccessprocess security advanced Access Security Add Auto-Number Field Type Form Instances ImageList Control Item Macros Menus RaiseEvent Recordset Top Values Variables Wrapper Classes msaccess email progressmeter Access2007 Copy Excel Export Expression Fields ImageList Join ListView Control Methods Microsoft Nodes Numbering System Records Security Split SubForm Table Tables Time Difference Utility Workgroup database function msaccess wizards tutorial Access Emails and Alerts Access Fields Access How Tos Access Mail Merge Access2003 Accounting Year Action Animation Attachment Binary Numbers Bookmarks Budgeting ChDir Color Palette Common Controls Conditional Formatting Data Filtering Database Records Defining Pages Diagram Disk Dynamic Lookup Error Handler External Filter Formatting Groups Hexadecimal Numbers Import Labels List Logo Macro Mail Merge Main Form Memo Monitoring Octal Numbers Operating System Paste Primary-Key Product Rank Reading Remove Rich Text Sequence SetFocus Summary Tab-Page Union Query User Users Water-Mark Word automatically commands hyperlinks iSeries Date iif ms-access msaccess msaccess alerts pdf files reference restore switch text toolbar updating upload vba code