Setting forms

D

David S.

Hello everyone,

I am looking for a way to set form properties programatically. I envision
running a module that will have predetermined form settings that is table
driven. Could you please give me a start by setting the following;

For a form
Set the property the RECORD SELECTORS to NO

For all the fields in a form
Set the property SPECIAL EFFECT to flat.

Thanks so much.

David S.
 
M

Marshall Barton

David said:
I am looking for a way to set form properties programatically. I envision
running a module that will have predetermined form settings that is table
driven. Could you please give me a start by setting the following;

For a form
Set the property the RECORD SELECTORS to NO

For all the fields in a form
Set the property SPECIAL EFFECT to flat.

Note that the form must be open to set its properties. If
you want the settings to be permanent, then it must be
opened in design view.

If you just want to set the properties for the current
instance of the form as it opens, then you can call the
procedure from the form's Open or Load event.

Assuming that your driving table contains the form's
ID/name, an indicator if the property is a form or control
property, the property's name, and the value you want to set
it to, then open a recordset on the table and loop through
it to set the property values. It could look something like
this air code:

Set rs = db.OpenRecordset( _
& "SELECT PropName, PropValue, ApplyTo " _
& "FROM drivingtable " _
& "WHERE FormName = """ & frm.Name & """")

Do Until rs.EOF
If rs!ApplyTo = "Form" Then
frm.Properties(rs!PropName) = rs!PropValue
Else
' Ignore errors for controls that do not have the
' the property you want to set.
On Error Resume Next
For Each ctl In frm.Controls
ctl.Properties(rs!PropName) = rs!PropValue
Next ctl
On Error GoTo somewhere
End If
Loop
 
K

Ken Snell

Inline....

--
Ken Snell
<MS ACCESS MVP>

David S. said:
Hello everyone,

I am looking for a way to set form properties programatically. I envision
running a module that will have predetermined form settings that is table
driven. Could you please give me a start by setting the following;

For a form
Set the property the RECORD SELECTORS to NO

Me.RecordSelectors = False

or

Forms!FormName.RecordSelectors = False
For all the fields in a form
Set the property SPECIAL EFFECT to flat.

Actually, there are controls on a form, not fields.

Dim ctl As Control
On Error Resume Next
For Each ctl in Me.Controls
ctl.SpecialEffect = 0
Next ctl
 
M

Marshall Barton

David said:
Thanks Marshall,
That was very helpful. I presume that I reference the openned (designed
view form) with

dim frm as form
frm = formname

Not quite. In general, you would use:

Set frm = Forms!formname

but, if the procedure is being called from an event
procedure in the form itself, you should make frm an
argument of the procedure and call it with:

SetFormProps Me
 

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