Full Version: "Bookmarking"
UtterAccess Forums > Microsoft® Access > Access Forms
JVanKirk
Another day..another question...
Is there a way to "bookmark" a record. The user for a db I created would like to be able to open to the last record he was on the next time he opens Access. Even further he would like to do so for each form. So if he was in the Inventory form, it would bookmark that record and reopen to it the next time he comes in and if he was in the orders form he would come back to the last record he was on in there!!! crazy.gif
If it can be done, great, if not, I have no heart burn telling this user..soryy..it's a no-go.
Thanks in advance,
Jason
fkegley
Yes, you could store the PK of the record that was open in a table when the form is closed. Then in the open event of the form, navigate to that record.
One table could do this, one field would be form name, one field would be PK. You would need DLookup in open event of form to fetch the PK of the record, then FindFirst probably to navigate to it.
JVanKirk
Frank,
Thanks, that's what I started trying to work out since posting. Will keep messing around in that direction I guess.
J
NoahP
See if the attached helps.

You'll need to use the On Open to call the sub to move to the last record viewed using:

MoveToLastViewedRecord Me.Name

and the form Unload event to call the sub to record the last record:

UpdateFormData Me.Name, Me.NameOfPKFieldHere

This is just set up for Long Integer (Autonumber) type PK's. No error trapping whatsoever. It does handle multiple users.
JVanKirk
Noah,
Always good to see your monicar in the replies. How are you?
I'll give it a shot. I think I understand most of the code you sent. I'll tyr to get it reconfiged for this db.
Thanks,
J
JVanKirk
Noah,
Not this under the appropriate events:
Private Sub Form_Open(Cancel As Integer)
DoCmd.Maximize
MoveToLastViewedRecord Me.Name

End Sub
____________________________________________________________
Private Sub Form_Unload(Cancel As Integer)
UpdateFormData Me.Name, Me.ItemID

End Sub
My PK field is the ItemID
Doesn't seem to be "remembering" where it's suppose to go when form opens back up. Just thought of something else..will check to see if it's writing anything to the tables... anyway, any thoughts in the meanttime??
Thanks,
J
NoahP
You have to enter the forms involved in tblForms.
JVanKirk
OK, wil give that a shot.
Is there anything in the Module that needs changed??
Thank you again, I'll get the forms input in the table and try that.
Jason
NoahP
Shouldn't need to change anything. Drop the module in the database, make the entries into tblForms, and call the subroutines in the appropriate events.
JVanKirk
Yeah, that seems to be working now (I Think). I get an error now stating I'm missing an operator and it has something to do with the event that's running on Form_Current:
Private Sub Form_Current()
If Me.txtOnHand.Value = Null Then
Me.txtOnHand.Value = DLookup("InvTotal", "qryMostRecentInvTotal", "[ItemID] = " & Forms!frmOrders!ItemID)
End If

End Sub
This sets the OnHand value to the most recent inventory total if it's currently Null. But, since the db is trying to set the ItemID to the last I think it's biffing up this event. I'm going to Rem this one out for now and see if the "bookmarking" is working. The OnCurrent and Open must run right on top of each other. Is there a way to keep this working? Has to be on Current so it checks when jumping through records...
Thanks,
Jason
JVanKirk
Noah,
etting a runtime error 2001
You cancelled the previous operation. When I hit debug I get this
Public Sub MoveToLastViewedRecord(frm As String)
Dim lngID As Long
Dim strFieldName As String
Dim strUser As String
Dim strForm As String
Dim lngForm As Long
Dim rs As Object
strUser = Environ("Username")
strForm = frm
strFieldName = Nz(DLookup("FieldToUse", "tblForms", "FormName='" & strForm & "'"), "")
If strFieldName = "" Then Exit Sub
lngForm = Nz(DLookup("FormID", "tblForms", "FormName='" & strForm & "'"), 0)
If lngForm = 0 Then Exit Sub
lngID = Nz(DLookup("FieldsValue", "tblFindRecords", "FormID = " & lngForm & _
" AND User = '" & strUser & "'"), 0)
If lngID = 0 Then Exit Sub
Set rs = Forms(strForm).Recordset.Clone
rs.FindFirst strFieldName & " = " & lngID
If Not rs.NoMatch Then
Forms(strForm).Bookmark = rs.Bookmark
End If
Set rs = Nothing
End Sub
The red line being the highlighted issue. Any ideas?
It's getting closer...
J
NoahP
Got any missing Library References?
JVanKirk
Not that I know of. Any way of checking?
NoahP
From the VBA Code window: Tools>>>References
JVanKirk
Noah,
oesn't seem like I'm missing any references. There's a big long list. Anything particular to look for?
J
JVanKirk
Also,

The On Unload event is working fine. Checked it a few times by going to a differant record, closing, then checking the table. That part works great, just can't get the On Open to fire right.

Thanks again Noah, I'll keep messing around with it till you think of something or I get it to run right.

J

Also, what does this part of the code do since this is where it errors at...

If Not rs.NoMatch Then
Forms(strForm).Bookmark = rs.Bookmark
End If
NoahP
That's what moves it to the correct record.
You would see a reference that is checked, but says MISSING next to it. Is the DAO 3.6 reference checked? If not, you need to check it and then move it up using the up arrow as far as it will go.
JVanKirk
Noah,
AO 3.6 is checked and moved up as far as possible. Nothing says missing next to it. I'm going to try stipping this down and posting it on here so maybe you can take a peek at it. I haven't been able to get it going.
J
JVanKirk
OK,
Here it is...
NoahP
Move the function to the On Load event instead of the On Open. Sorry for the slow reply...
JVanKirk
Noah, that made sense the second I read it, will go see if it works....
JVanKirk
Noah, moved it to the On Load event and got the same thing. Made a quick button on the form to run that code and it works beautifully!! Did it work for you using my db moving it to the On Load?
NoahP
Yep, sure did. But, I'm using 2000. It worked in the On Open in 2000....
Not sure what's going on. My old machine with 97 on it bombed out on me and I've yet to reinstall it, so I can't directly test it...
JVanKirk
I hear that, we moved to Office 2003 from 97 while I was in USAREC at Fort Knox yet and a lot of "bugs" in 97 db's suddenly started working just fine. Not going to happen too soon here I fear. Interesting that the code works OK if I put it on a button, which may be the final outcome for this app, but it won't work on the OnOpen or OnLoad events.
nyway, thanks for the help with it. I'll just keep playing around till I figure something out.
J
NoahP
Try going to a blank record first using DoCmd.GotoRecord,,acnewrec just before the code runs to move to the last viewed record. May not work, but I think worth a shot. It acts like the recordsource hasn't loaded yet and that is what causes the error. Thinking OnOpen too early is why I suggested try OnLoad.
JVanKirk
Noah, today you are a god!! LOL..That works!!!
Thanks buddy, I had tried this all the way down to OnActivate and it was still erroring out.
It's kickin now.
Thank you!
J
NoahP
You are welcome! Definitely nothing god-like about me, but I'm glad you got it working!
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.