Default Data

S

Serg

Hi everybody,

Every time when i open my access form, i want to see the same record that i
had seen before i closed this form last time. I 've created a special
table where i am going to keep keys of this record for every form i use. But
i dont know how i can reach this table from these forms, because any form
allows to have only one Record Source, but i need to save the data every
time when i close the form and read it when i open the form. I dont want to
use any subform to keep this data. Any ideas will be very much appreciated.

Thanks
Serg
 
G

Graham Mandeno

Hi Serg

I don't know what is the structure of your "special table, but let's say it
has a primary key "FormName" and another field "SavedKey". Let's say the
name of the table is "LastRecord".

You can then use the Form_Unload event procedure to save the primary key of
the current record:

CurrentDb.Execute "Update [LastRecord] set SavedKey=" & Me![PK field] _
& " where FormName='" & Me.Name & "'"

And you can use the Form_Load event procedure to retrieve the saved key
value and navigate to the correct record:

Dim vLastKey as Variant
vLastKey = DLookup( "[SavedKey]", "[LastRecord]", _
"FormName='" & Me.Name & "'" )
If Not IsNull(vLastKey) then
with Me.RecordsetClone
.FindFirst "[PK Field]=" & vLastKey
If not .NoMatch then Me.Bookmark = .Bookmark
End With
End If
 
S

Serg

Hi Graham
Thank you very much for your help. I appreciate this very much. I tryed to
save my key using the Form_Unload event procedure and algorithm you wrote to
me. But i always got error message - "Too few parameters. Expected 1". But i
dont know why. Any ideas?

Thanks
Serg
 
S

Serg

Hi Graham

I found my mistake and everything is working perfect now. Thank you for your
help again. I appreciate this very much.

Serg
 
G

Graham Mandeno

Hi Serg

I guess your primary key was text, not numeric. I'm glad you figured it
out. :)
 

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