Referencing Properties rather than controls in a Report

cable

Access For My Sins
Local time
Today, 22:38
Joined
Mar 11, 2002
Messages
226
I've never liked using hidden controls to store variables, so I was wondering if I created public property get/let's in the form, can a report reference these instead?

If so what's the syntax to use?
 
You can create Custom Properties on Forms to store values in them and retrive them later.

Forms, Reports etc. are known as Document Objects under the Container group Object of Database Object. Check the following sample procedure that create a Custom Property on the Employees form with the name EmpCode with data type Long Integer and with an initial value of 1:

Code:
Public Function CreateProp()
Dim db As Database, doc As Document
Dim prop As Property

Set db = CurrentDb
Set doc = db.Containers("Forms").Documents("Employees")
Set prop = doc.CreateProperty("EmpCode", dbLong, 1)
doc.Properties.Append prop
doc.Properties.Refresh

Set doc = Nothing
Set prop = Nothing
Set db = Nothing

End Function

You can create as many custom properties as you like. After creating them you can save values in them. Whenever you open the form next time you can read them back or update them with fresh values.

It is not necessary to keep the Form in open state to read these values from Report Module/Standard Module based procedures.

For more details visit this page: Saving Data on Form not in Table.

A Custom Property based Form for creating custom Colors: www.msaccesstips.com/2010/10/create-your-own-color-palette.html
 
Last edited:

Users who are viewing this thread

Back
Top Bottom