Limiting Access to Buttons

Demona

How was that for ya?
Local time
Today, 11:08
Joined
May 25, 2003
Messages
27
Hi Guys & Gals

I was wondering if it is possible to limit access to buttons and other areas on a database without using the built in UserGroups of Access.

I have a script that requires a user name and password and was wondering at this point whether a person could limit things like password changing or user deletion.

After running through many many messages in this forum I found something which I tried to modify:

code:
Private Sub AccessLevel()

If InStr(AccessLevel(), "Administration") > 0 Then
Me.[Forms]![frmentry]![Password Maintenance Button] = True
Else
Me.[Forms]![frmentry]![Password Maintenance Button] = False
End If

End Sub

This code however seems to do nothing. When I walk through the debug code it goes through it but nothing happens no matter who is logged on.

My Logon script passes the following:
RealName, UserName, Password, AccessLevel when its looked up in the table. Can this be done?

In the table the following AccessLevels are: Administration, Maintenance, & User.

Thanks for any help
 
The code will be ok but you need to modify what you are searching in. Depending on if you have the access level open anywhere ie on a form somewhere, you may be able to use a Dlookup to get it. You will have to have a reference somewhere to who is logged in to get any restrictions to work.
How I do this is to have a login splash form which stays open (but hidden) throughout the whole of the application use. It is then just a matter of referencing the form control
In your case:

Code:
Private Sub AccessLevel() 
dim strCurrentUserAccess as string
strCurrentUserAccess = Dlookup("[AccessLevel]", "YourTableName", "[UserName] = '" & Forms!LoginForm!UserNameControl & "'")

If instr(strCurrentUserAccess, "Administration") > 0 Then 'if more than one access level per user
If strCurrentUserAccess = "Admininstarion" then 'if one level access
Me.[Forms]![frmentry]![Password Maintenance Button] = True 
Else 
Me.[Forms]![frmentry]![Password Maintenance Button] = False 
End If 

End Sub
 
Little more help ... pretty please

Thank you for responding. I am learning a termendous amount from all the members of this forum. I think I understood what you did, but now I'm getting errors that I am having problems trapping.

Here is my revised code

Private Sub Form_Load()

Dim strCurrentUserAccess As String
strCurrentUserAccess = DLookup("[AccessLevel]", "Specific Users", "[UserName] = '" & Forms!Login!txtName & "'")

'--if more than one access level per user
If InStr(strCurrentUserAccess, "Administration") > 0 Then
[Forms]![Password Maintenance]!Add_New_User_Button.enable = True
[Forms]![Password Maintenance]!Delete_User_Button.enable = True
Else
[Forms]![Password Maintenance]![Add New User Button].enable = False
[Forms]![Password Maintenance]![Delete User Button].enable = False
End If

End Sub

the error says : Runtime error 438

Object doesn't support this property or method.

And for some reason access doesn't seem to have a listing for error codes.

Thanks
 
Does anyone know where I can find a complete list of error codes for Access as the help doesn't seem to have a very indepth listing.
 
Demona said:
Does anyone know where I can find a complete list of error codes for Access as the help doesn't seem to have a very indepth listing.

Access provides code to provide you with a list of all trappable errors.

Here's the code from A97.

Code:
Sub CreateErrorsTable()
	Dim dbs As Database, tdf As TableDef, fld As Field
	Dim rst As Recordset, lngCode As Long
	Const conAppObjectError = "Application-defined or object-defined error"

	' Create Errors table with ErrorNumber and ErrorDescription fields.
	Set dbs = CurrentDb
	Set tdf = dbs.CreateTableDef("Errors")
	Set fld = tdf.CreateField("ErrorCode", dbLong)
	tdf.Fields.Append fld
	Set fld = tdf.CreateField("ErrorString", dbText, 255)
	tdf.Fields.Append fld

dbs.TableDefs.Append tdf
	' Open recordset on Errors table.
	Set rst = dbs.OpenRecordset("Errors")
	' Loop through first 1000 Visual Basic error codes.
	For lngCode = 1 To 1000
		On Error Resume Next
		' Raise each error.
		Err.Raise lngCode
		DoCmd.Hourglass True
		' Skip error codes that generate application or object-defined errors.
		If Err.Description <> conAppObjectError Then
			' Add each error code and string to Errors table.
			rst.AddNew

rst!ErrorCode = Err.Number
			rst!ErrorString = Err.Description
			rst.Update
		End If
		' Clear Err object.
		Err.Clear
	Next lngCode
	' Close recordset.
	rst.Close
	DoCmd.Hourglass False
	MsgBox "Errors table created."
End Sub


Put it in a module and run it - it creates a table for you.
 

Users who are viewing this thread

Back
Top Bottom