Access 97 - When opening, returning a form to the prior state when the ap was closed

G

George

About 8 years ago when I last used Access 97 I wanted to be able to store
the key fields (autonumber/long integer) into a table which could be read
again after startup. This would restore the user to the place on a form
where he left off in a prior session.

When frmMain first opens after the ap is started all fields are blank.

frmMain has these relevant controls:

frmMain!cboSection - SectionID (PK)
frmMain!txtQuestion - QuestionID (PK)
etc.

tblStoredValues
field 1 = StoredValueID (Autonumber)
field 2 = ControlName (Text)
field 3 = ControlValue (FK)

I remember setting up a table which contained the control name and would be
updated with the PK value each time the user moved off the control. But I
forgot how I stored the PK value. A line of SQL code in the after update
event maybe. When each form opened it looked up the values of these fields
and set the control to the saved value. Maybe I used DLookup. Need an
example of what goes where. Thanks.
 
J

Jeanette Cunningham

Hi George,
you could use the Current event of the form to run an update query to put
the PK value in the table.

strsql = "update tblStoredValues " _
& "set tblStoredValues.[field 1] = " & Me.NameOfPKField& ""
CurrentDb.Execute strsql, dbfail on error

When you want to recall the value from the table, you can use DLookup.
Something like this untested air code:

Dim lngPK as long
lngPK = Nz(DLookup("[field 1]", "tblStoredValues"),0)
DoCmd.OpenForm "frmMain", , ,"[PK] = " & lngPK & ""


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top