save any property from vba

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi everybody
i can use anyones help

i need a possibility to have my forms open on the last record that was used
in the previous session. i was thinking of setting the forms tag property to
the primarykey value and search for it onOpen, but as soon as the form
closes, the tag (as well as other properties) expire.

thanks in advans
 
I suggest you'd be better off using a one row table which
you empty (delete *) then store the last key value when the
form closes then pick it up (if not null) when the form
opens.

IIRC you need to open the form in design view in your code
to permanently store a new value for a property like Tag.

--
Nick Coe (UK)
http://www.alphacos.co.uk/ AccHelp + pAnimal
http://www.mrcomputersltd.com/ Repairs Upgrades

In YisMan typed:
 
You could create a table that will hold the primary key of the last record
used. In the Close event of the form, update the table with the current
record's key. When you load the form, make that record the current record.
To expand on that, if you want a consistent look and feel so that would be
the behaviour of all your forms, then you could have two fields in the
record, the form name and the last key. Then do your search by formname.
 
You could try the following.

Before Exiting the Application set the primary key:

Sub SaveLastUsedPrimaryKey(primaryKey As String)
SaveSetting appname:="YourAppName", Section:="Startup",
Key:="LastPrimaryKey", setting:=primaryKey
End Sub

And then in the on open event get the setting from the registry:

Function GetLastUsedPrimaryKey() As String
GetLastPrimaryKey = GetSetting(appname:="YourAppName",
Section:="Startup", Key:="LastPrimaryKey")
End Function


Good Luck.
 
thanks, i loved your idea of devoting a table for form-value pairs. though i
still think the best way wouldve been to save the tag property.
are you sure its impossible?
 
You can use the AccessObjectProperties collection. In the example below,
'TestID' is the name of the primary key field ...

Private Sub Form_Open(Cancel As Integer)

Dim aob As AccessObject
Dim aop As AccessObjectProperty
Dim rst As DAO.Recordset

Set aob = CurrentProject.AllForms(Me.Name)
For Each aop In aob.Properties
If aop.Name = "LastRecord" Then
Set rst = Me.RecordsetClone
rst.FindFirst "TestID = " & aop.Value
If Not rst.NoMatch Then
Me.Bookmark = rst.Bookmark
End If
Exit For
End If
Next aop

End Sub

Private Sub Form_Unload(Cancel As Integer)

Dim aob As AccessObject

If Not Me.NewRecord Then
Set aob = CurrentProject.AllForms(Me.Name)
aob.Properties.Add "LastRecord", Me.TestID
End If

End Sub
 
thanks,
sounds intriguing, this properties thing, ill look it up in help for more
specs
but seeing that youre a mvp id like to ask isnt dao supposed to become
extinct one of these days? (i take great card to avoid it,due to this
assumption)
 
Everything will become extinct 'one of these days' but DAO will continue to
be supported at least as long as 'classic' ADO. You can declare 'rst As
Object' if you want, and the code will execute without any explicit
reference to the DAO object library. But the RecordsetClone and Recordset
properties of the Form object will still be returning a DAO Recordset
object, unless you have explicitly assigned an ADO recordset to the
Recordset property of the form. See the URL below for an interesting article
on these properties ...

http://www.trigeminal.com/usenet/usenet022.asp?1033

Basically, trying to avoid DAO in an MDB is an exercise in futility, and
trying to avoid DAO in favour of 'classic' ADO is pointless, as 'classic'
ADO isn't going to be around any longer than DAO anyway, while ADO.NET is a
new and very different technology with little in common with 'classic' ADO
other than three letters in its name.
 
Back
Top