[AccessD] Save my (form) property

jwcolby jwcolby at colbyconsulting.com
Tue Jun 26 12:00:50 CDT 2007


I want to iterate through and store the same value in one specific property
of all of my forms (the help file property).  I wrote this code ages ago but
who knows where it went.  So I wrote it again and here it is:

Function SetFormProperty(strPrpName As String, varValue As Variant)
Dim db As DAO.Database
Dim doc As DAO.document
Dim frm As Form

    Set db = CurrentDb	'Get a pointer to the database (this will be DAO of
course)
    For Each doc In db.Containers("forms").Documents	'and a pointer to
each doc in the forms document collection
    	  DoCmd.OpenForm doc.name, acDesign			'Open the
form in design view
        Set frm = Forms(doc.name)				'now get a
pointer to the form
        Debug.Print frm.Properties(strPrpName)		'display the old
property value
        frm.Properties(strPrpName) = varValue		'Set the property to
the new value
        Debug.Print frm.Properties(strPrpName)		'display the newly
set value
        Set frm = Nothing					'Get rid of
my pointer holding the form open
        DoCmd.Close acForm, doc.name, acSaveYes		'Close the form
saving changes
    Next doc							'Go round
the block again.
End Function

You can, if you wish actually feed the TYPE of object in, but then you need
to deal with whether you open a report or a form.  You can also just write a
similar function to open reports etc.

John W. Colby
Colby Consulting
www.ColbyConsulting.com 




More information about the AccessD mailing list