My Assistant
![]() ![]() |
|
|
Aug 7 2007, 07:57 PM
Post
#1
|
|
|
UtterAccess Addict Posts: 136 |
I have a form that scrolls through a table set, each with it's own unique record ID.
How do I set it that when the form opens, it finds the last record worked on? I heard bookmark, but don't know how to use this function. Any help would be greatly appreciated. |
|
|
|
Aug 7 2007, 08:27 PM
Post
#2
|
|
|
UtterAccess VIP Posts: 18,396 From: Oklahoma City, Oklahoma |
The Basics are:
1) wqhen the form closes, save the unique record ID. I normally use a table. 2) When the form loads, look to see if ther eis a saved unique record ID for the current user. If there is, then "find" the record. If it exits in the current record set for the form then move the bookmark to that record. Sample code to find a record" CODE Me.RecordsetClone.FindFirst "[PrimaryKeyFeild] = " & lngPrimaryKeyToFind
If Me.RecordsetClone.NoMatch Then MsgBox "Code not fiinf record id: " & lngPrimaryKeyToFind Else Me.Bookmark = Me.RecordsetClone.Bookmark End If You will just need to add code to sore the Primary Key value and then retrieve. Edited by: HiTechCoach on Tue Aug 7 21:51:43 EDT 2007. |
|
|
|
Aug 8 2007, 09:10 AM
Post
#3
|
|
|
UtterAccess VIP Posts: 9,277 From: Wisconsin |
Expanding a bit on Boyd's advice...
If this is just one person at a time (or you only want to store one "last record viewed" record), you can set up a table to store the primary key value of the record. tblUserData intLastViewedID (Long Integer) strProperty (string) This table will have a single record in it. Put the phrase Last_Record_Viewed in the strProperty field of the first record of the table. This will help make sure that you only store one unique value in this table. When the form is closed, run a simple Update query to set the value of the intLastViewedID field to the primary key value of the record currently being viewed: DoCmd.RunSQL "UPDATE [tblUserData] SET [intLastViewedID] = '" & Trim(Me.intRecordID) & "' WHERE [strProperty] = 'Last_Record_Viewed'" In this example, I've got a textbox control on the form called intRecordID. It can be hidden from the user and still function for this code. When the form opens, grab the target record ID from the tblUserData table, using a DLookup: lngPrimaryKeyToFind = DLookup("[intLastViewedID]", "tblUserData", "[strProperty] = 'Last_Record_Viewed'") Then, use the code that Boyd suggested to move to the record (if it still exists). Dennis |
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 21st May 2013 - 02:51 PM |