Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pull up last viewed or edited form

Status
Not open for further replies.

SeaweedOPM

Technical User
Nov 19, 2004
53
US
I have a form that pulls data from one table that contains about 20000+ records. When I enter the form it always starts me at 1. it would be nice if it could put me where i left off. Or any other way. I was thinking about putting a check button and adding a whole column in the table that was true/false that was labeled something like StartHere and then on the form open command have it open on [starthere] = true. If anyways has any ideas that would be great.
 
How are ya zboyles . . . . .

The only problem here is [blue]lue]where to store the last used value[/blue][/blue]. There's a way to save to the Registry (works well) but I frown on anything to do with it. So I'mm gonna go with an independent table. The table is going to hold a [blue]single value[/blue] . . . the last recorder position in the form.

[ol][li]So make a new table with the following properties:
[blue]Field Name [purple]LastRecID[/purple]
Data Type [purple]Autonumber[/purple] Make it the PrimaryKey[/blue][/li]
[li][blue]Field Name [purple]LastID[/purple]
Data Type [purple]Whatever you used form PrimaryKey in form[/purple]
Field Size [purple]Whatever you used form PrimaryKey in form[/purple][/blue]
Save & name the table [purple]tblLastRec[/purple]. Close.[/li]
[li]Open the new table and enter a [blue]single value for LastID[/blue]. Save &close the table.

Note: In all code that follows, [blue]you[/blue] substitute proper names in [purple]purple[/purple] Also, the code assumes your [blue]PrimaryKey is numeric[/blue].[/li]

[li]Open the form in design, and in the [blue]Load Event[/blue] of the form, copy/paste the following code:
Code:
[blue]   Dim rst As DAO.Recordset, ID
   
   ID = DLookup("[LastID]", "tblLastRec")
   
   If ID = 0 Then
      DoCmd.RunCommand acCmdRecordsGoToNew
   Else
      Set rst = Me.RecordsetClone
      rst.FindFirst "[purple][b]YourPrimaryKeyName[/b][/purple] = " & ID
      Me.Bookmark = rst.Bookmark
      Set rst = Nothing
   End If[/blue]
[/li]
[li]Next, in the [blue]UnLoad Event[/blue] of the form, copy/paste the following code:
Code:
[blue]   Dim SQL As String
   
   SQL = "UPDATE tblLastRec SET LastID = "
   
   If Me.NewRecord Then
      SQL = SQL & 0 & ";"
   Else
      SQL = SQL & [purple][b]YourPrimaryKeyName[/b][/purple] & ";"
   End If
   
   DoCmd.RunSQL SQL[/blue]
[/li][/ol]
[blue]Thats it . . . . give it a whirl & let me know . . . .[/blue]

Calvin.gif
See Ya! . . . . . .
 
Man that works soo good! I was scrolling through like 20000 records. This helps out a bunch thanks!
 
zboyles . . . . .

Great! . . . .

You may want to [blue]consider[/blue] adding a few navigation controls:

[purple]Goto Top
Goto Middle
Goto New Record
Jump Forward/Back a predetermined # of records (with key repeat)
[/purple]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top