Hi
I created a pretty simple databse, which is used by several users. The main functions are set up, however as it contains some macros and modules, I would like to protect the structure of the database.
I have an opening screen, and the database is set up to automaticcaly open that opening screen when someone opens it up.
I thought it would be easier if I could admin rights to 1-2 users. The main point is that the person who has admin rights, does not neccessary edits the database structure, mainly he is just using it and filling up with information.
So, I thought, the best solution could be if could add 2 buttons to this opening screen: Admin Mode ON and Admin Mode OFF. These buttons should be visible only to those users, who have admin rights.
When the database opens up, the ribbon, the properties, and every editing buttons should be disabled, but when the person clicks on the button, enables those features.
Simple users could not see these Admin mode buttons, neither turn it on or off.
I started to examine this solution:
however it's not perfect, because it automatically turns on or off the ribbon etc if the userID matches, but admins does not neccessarily want to edit the database, just use it, so if I could give them some chance to select between modes, that would be perfect.
I tried to modify the above code, without success - tried to mix it with the below sub:
Private Sub Form_Open(Cancel As Integer)
If "Userid=Admin (more explicit code inserted here) = Then
bLock.Visible = True
bUnLock.Visible = True
End If
End Sub
can someone please help me how to create the above mentioned function?
The best solution would be if I could have a separate table listing the userIDs of all of the admins, and the Admin mode button would appear for everyone who are lsited in the table.
I guess updating the table would be much easier the updating the array of the users in the code.
thanks in advance for the help.
I created a pretty simple databse, which is used by several users. The main functions are set up, however as it contains some macros and modules, I would like to protect the structure of the database.
I have an opening screen, and the database is set up to automaticcaly open that opening screen when someone opens it up.
I thought it would be easier if I could admin rights to 1-2 users. The main point is that the person who has admin rights, does not neccessary edits the database structure, mainly he is just using it and filling up with information.
So, I thought, the best solution could be if could add 2 buttons to this opening screen: Admin Mode ON and Admin Mode OFF. These buttons should be visible only to those users, who have admin rights.
When the database opens up, the ribbon, the properties, and every editing buttons should be disabled, but when the person clicks on the button, enables those features.
Simple users could not see these Admin mode buttons, neither turn it on or off.
I started to examine this solution:
Option Compare Database
Option Explicit
Global sLogon As String
Public Function StartUp()
Dim Designer As String
Dim Restart As Boolean
Dim stAppName As String
Designer = "yourlogonhere"
FIND_USER
If sLogon = Designer Then
Restart = UnlockStartup
Else
Restart = LockStartup
End If
If Restart Then
'Close database and re-open
stAppName = "MSAccess.exe " & CurrentDb.Name
Call Shell(stAppName, 1)
DoCmd.Quit
Else
If sLogon <> Designer Then DoCmd.OpenForm "TitleForm"
End If
End Function
-----------------------------------
Sub FIND_USER()
On Error GoTo ERR_FIND_USER
Dim UserParam$
Dim sChk As String
Dim CurrentAuditor As String
UserParam$ = Environ("S_USER")
If UserParam$ = "" Then UserParam$ = Environ("USERNAME")
sLogon = UCase$(UserParam$)
EXIT_FIND_USER:
Exit Sub
ERR_FIND_USER:
MsgBox Error$
Resume EXIT_FIND_USER
End Sub
---------------------------------------------
Function LockStartup() As Boolean
Dim Restart As Boolean
Restart = False
ChangeProperty "StartupShowDBWindow", dbBoolean, False, Restart
ChangeProperty "AllowBuiltinToolbars", dbBoolean, False, Restart
ChangeProperty "AllowFullMenus", dbBoolean, False, Restart
ChangeProperty "AllowToolbarChanges", dbBoolean, False, Restart
ChangeProperty "AllowBreakIntoCode", dbBoolean, False, Restart
ChangeProperty "AllowSpecialKeys", dbBoolean, False, Restart
ChangeProperty "AllowBypassKey", dbBoolean, False, Restart
Application.SetOption "Show Hidden Objects", False
LockStartup = Restart
End Function
-----------------------------------------------
Function UnlockStartup() As Boolean
Dim Restart As Boolean
Restart = False
ChangeProperty "StartupMenuBar", dbText, "(default)", Restart
ChangeProperty "StartupShowDBWindow", dbBoolean, True, Restart
ChangeProperty "StartupShowStatusBar", dbBoolean, True, Restart
ChangeProperty "AllowBuiltinToolbars", dbBoolean, True, Restart
ChangeProperty "AllowFullMenus", dbBoolean, True, Restart
ChangeProperty "AllowToolbarChanges", dbBoolean, True, Restart
ChangeProperty "AllowBreakIntoCode", dbBoolean, True, Restart
ChangeProperty "AllowSpecialKeys", dbBoolean, True, Restart
ChangeProperty "AllowBypassKey", dbBoolean, True, Restart
UnlockStartup = Restart
End Function
-------------------------------------------
Function ChangeProperty(strPropName As String, varPropType As Variant, varPropValue As Variant, Restart As Boolean) As Integer
Dim dbs As Database, prp As Property
Dim CurrentPropVal As Variant
Const conPropNotFoundError = 3270
Set dbs = CurrentDb
On Error GoTo Change_Err
CurrentPropVal = dbs.Properties(strPropName)
If CurrentPropVal <> varPropValue Then
dbs.Properties(strPropName) = varPropValue
Restart = True 'need to restart database
End If
ChangeProperty = True
Change_Bye:
Exit Function
Change_Err:
If Err = conPropNotFoundError Then 'Property not found.
Set prp = dbs.CreateProperty(strPropName, varPropType, varPropValue)
dbs.Properties.Append prp
Resume Next
Else
' Unknown error.
ChangeProperty = False
Resume Change_Bye
End If
End Function
however it's not perfect, because it automatically turns on or off the ribbon etc if the userID matches, but admins does not neccessarily want to edit the database, just use it, so if I could give them some chance to select between modes, that would be perfect.
I tried to modify the above code, without success - tried to mix it with the below sub:
Private Sub Form_Open(Cancel As Integer)
If "Userid=Admin (more explicit code inserted here) = Then
bLock.Visible = True
bUnLock.Visible = True
End If
End Sub
can someone please help me how to create the above mentioned function?
The best solution would be if I could have a separate table listing the userIDs of all of the admins, and the Admin mode button would appear for everyone who are lsited in the table.
I guess updating the table would be much easier the updating the array of the users in the code.
thanks in advance for the help.