Restricting Access database users from seeing Switchboard Reports

  • Thread starter Thread starter Pedw4220
  • Start date Start date
P

Pedw4220

I have assigned four AccessLevels to my database. I only want those with
Admin - AccessLevelID 4 to be able to view the reports on the Switchboard.
I've tried to write the code, with no luck. I've tried different Event
Properties etc. On my Switchboard Items fields, Switchboard ID is 4,
ItemNumber is 0, ItemText is Reports, Command is 0 and Argument is blank.

upload If AccessLevelID = 4 Then
Me.[Argument].[4].Visible = True
Else
Me.[Argument].[4].Visible = False
End If
 
On Tue, 9 Mar 2010 13:02:01 -0800, Pedw4220

There are several philosophies about how to do this. I typically don't
mind users can click a button, but they can still not run the report.
So I write this code in the Report_Open event. The Open event has a
convenient Cancel property which you can set if the level is not what
you want:
private sub report_open(Cancel as Boolean)
if GetAccessLevel() <> enumAccessLevels.Admin then
Cancel = True
Msgbox "Yo! Not for your eyes.", vbCritical
end if
end sub

Note the use of GetAccessLevel: a public function you write in a
standard module, returning the access level. Convenient because with 1
line of code you can call it from anywhere.

Also note the use on an enum to hold the access levels. I'm thinking
of something like this in a public module:
Enum enumAccessLevels
ReadOnly = 1
User = 2
PowerUser = 3
Admin = 4
End Enum
That way your code becomes self-documenting, there is intellisense,
and it will be much easier to add access levels later, or move the
values around.

It now follows that the return type of GetAccessLevel is this enum:
public function GetAccessLevel() as enumAccessLevels

-Tom.
Microsoft Access MVP
 
Back
Top