Record & User Specific Behaviour For A Form

  • Thread starter Thread starter Kevin
  • Start date Start date
K

Kevin

Hi,

I need advice on whether it is possible to achieve the
following in Access 97 :

I need to set up a form for viewing, inserting and
modifying records in a table so that it's behaviour varies
( in terms of what fields of the record are editable and
what buttons on the form are activated etc.) based on the
following :

1) The user's login ID, which I'd need to access each time
a record from a table was viewed and which would be used
to look up bespoke roles stored in another table in
Access (How do I get at the user's ID for someone logged
into my split, User Level Secured database?) which would
in turn govern which fields of the record were editable as
well as the appearance or otherwise of buttons on the form
permitting the user to take certain actions.

2) The state of the record being viewed in the form which
would be stored in a field in the record being viewed.

Any informaation on how easy the above would be and any
pointers or examples would be appreciated.
 
Kevin said:
Hi,

I need advice on whether it is possible to achieve the
following in Access 97 :

I need to set up a form for viewing, inserting and
modifying records in a table so that it's behaviour varies
( in terms of what fields of the record are editable and
what buttons on the form are activated etc.) based on the
following :

1) The user's login ID, which I'd need to access each time
a record from a table was viewed and which would be used
to look up bespoke roles stored in another table in
Access (How do I get at the user's ID for someone logged
into my split, User Level Secured database?) which would
in turn govern which fields of the record were editable as
well as the appearance or otherwise of buttons on the form
permitting the user to take certain actions.

2) The state of the record being viewed in the form which
would be stored in a field in the record being viewed.

Any informaation on how easy the above would be and any
pointers or examples would be appreciated.

This is easy enough. Since the record's state may change as the user is
editing it, I'd recommend creating a separate function or subroutine in
the form's code module to handle the evaluation and set control
properties. You would call this procedure from the form's Current event
and from the AfterUpdate event of any control that may affect the state.

Since you've implemented user-level security, you can use the
CurrentUser() function to get the ID of the current user, so that's not
a problem. Or, since every user must be in one or more security groups,
you may be able to set the form's state based on whether or not the
current user is in a particular group. That would be more flexible, to
my mind, since then you wouldn't have to modify the form every time you
add a new user. For example, I have controls on some forms that are
enabled or not depending on whether the user is in the Admins group.
Note that, because a user may be in more than one group, there's no way
to ask, "What group is the current user in?" Instead you must ask, "Is
the current user in group X?" I have a DAO-based function to do this,
which I can post if you like; or you can search Google Groups (
http://groups.google.com ) for previous postings on the subject.

The state of the record being viewed is, of course, available for
inspection by testing the values of the controls on the form. If a
field is in the form's recordset but there's no control bound to it, you
can still access it as though it were a property of the form; e.g.,

If Me.SomeField = "somevalue" Then
' ... do something ...
End If

Properties you might control using your routine might include

For the form:
AllowEdits
AllowAdditions
AllowDeletions

For form sections
Visible (can be seen)

For controls
Locked (allow/disallow changes)
Enabled (can receive focus)
Visible (can be seen)
BackColor, ForeColor, SpecialEffect ... (control appearance)

.... and doubtless others I haven't thought of.

One thing to be aware of is that, on a continuous form, any change to a
control's properties applies to *all* copies of that control displayed
on that form; that is, the properties set for the current record apply
to all displayed records. Aside from a few cute tricks you can play,
you can't control formatting on a record-by-record basis on continuous
forms in Access 97. In A2K or later, you can use Conditional Formatting
to control some format properties on a record-by-record basis.
 
Back
Top