Open Form to last viewed

ECEK

Registered User.
Local time
Today, 16:16
Joined
Dec 19, 2012
Messages
717
The subject pretty much says it all!

I have a form [frmdays] with a [uniqueID] Enabled: No Locked:Yes

OnClose send the [uniqueID] (of the page that I'm on)to a holding Table [tblhld].

OnOpen Goto record that matches in the [tblhd]

Thanks in advance.
 
Presuming the table contains a single record, on close run an update query with the current record. When opening, adapt this but get the record ID with a DLookup():

http://www.baldyweb.com/Bookmark.htm
 
Last edited:
My question is how do I do it !!!!!
 
Did the thoughts in post 3 not help?
 
1. i suggest you add another field on your tblHld, aside from having uniqueID field add a field called FormName (short text).

2. On top of your form module declaration (just below Option Compare Database or Option Explicit), declare a private variable to hold your UniqueID

Private lngUniqueID as Long

3. OnCurrent event of your form (frmDays):

Private Sub Form_Current()
lngUniqueID = Me.UniqueID
End Sub

4. On your form On Load event:

Private Sub Form_Load()

Dim lngRecordID As Long

lngRecordID = Nz(DLookup("UniqueID", "tblHld", "[FormName] = '" & Me.Name & "'"), 0)

If lngRecordID > 0 Then
DoCmd.GoToRecord acActiveDataObject, Me.Name, acGoTo, lngRecordID
End If

End Sub


5. On your form's Unload event:

Private Sub Form_Unload(Cancel As Integer)

Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb
Set rs = db.OpenRecordset("Select * from tblHld Where [FormName] = '" & Me.Name & "';")

With rs
If .RecordCount > 0 Then
.Edit
Else
.AddNew
![FormName] = Me.Name
End If
![UniqueID] = lngUniqueID
.Update
End With

Set rs = Nothing
Set db = Nothing

End Sub
 
OK Im going to give this a go. Sorry for the delay in responding...other stuff !!!

So Ive managed to get to 2.
Ive created a table (tblhld) with uniqueID (number) and FormName (text)

Where do I find my "form module declaration" on my form (frmdays) ?
 
while on form design, click Event on the tab, click on the elipses beside the event you want to work on, ie. On Load, Current, On Unload. then chose code builder, paste the code which i have provided.
 
I have entered my frmdays and right clicked properties and then the tab event to access the relevant events list however I still don't understand ....

2. On top of your form module declaration (just below Option Compare Database or Option Explicit), declare a private variable to hold your UniqueID
 
after this line:
Option Compare Database

put this line below:
Private lngUniqueID as Long

sorry i have a hard time expressing myself in english.
 

Users who are viewing this thread

Back
Top Bottom