Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

enable shift key depending on who logs in

Status
Not open for further replies.

hellohello1

Technical User
Jun 30, 2006
110
US
I'm using Access 2003. I have User Level Security set on my database and users need to open a batch file that contains the mdw switch in order to open my database.

I'm trying to automatically disable the Start Up key for all users except those logged in as dba.

I know the code to disable and enable the Shift key (below), but I don't know where to put my If statement:

If CurrentUser() = "dba" Then
call ap_EnableShift()
else
call ap_DisableShift()
End If

I don't want a button to enable or disable the Shift key. I would like it to happen automatically if possible.

What I mean is, now users click on the batch file and they get a Logon Name and Password dialog box. If they enter the 'dba' Logon Name and Password, I would like the Shift Key to work. If they don't enter the 'dba' Logon Name and Password, I would not like the Shift key to work.

Function ap_DisableShift()
'This function disable the shift at startup. This action causes
'the Autoexec macro and Startup properties to always be executed.

On Error GoTo errDisableShift

Dim db As DAO.Database
Dim prop As DAO.Property
Const conPropNotFound = 3270

Set db = CurrentDb()

'This next line disables the shift key on startup.
db.Properties("AllowByPassKey") = False

'The function is successful.
Exit Function

errDisableShift:
'The first part of this error routine creates the "AllowByPassKey
'property if it does not exist.
If Err = conPropNotFound Then
Set prop = db.CreateProperty("AllowByPassKey", _
dbBoolean, False)
db.Properties.Append prop
Resume Next
Else
MsgBox "Function 'ap_DisableShift' did not complete successfully."
Exit Function
End If

End Function

Function ap_EnableShift()
'This function enables the SHIFT key at startup. This action causes
'the Autoexec macro and the Startup properties to be bypassed
'if the user holds down the SHIFT key when the user opens the database.

On Error GoTo errEnableShift

Dim db As DAO.Database
Dim prop As DAO.Property
Const conPropNotFound = 3270

Set db = CurrentDb()

'This next line of code disables the SHIFT key on startup.
db.Properties("AllowByPassKey") = True

'function successful
Exit Function

errEnableShift:
'The first part of this error routine creates the "AllowByPassKey
'property if it does not exist.
If Err = conPropNotFound Then
Set prop = db.CreateProperty("AllowByPassKey", _
dbBoolean, True)
db.Properties.Append prop
Resume Next
Else
MsgBox "Function 'ap_DisableShift' did not complete successfully."
Exit Function
End If

End Function


Thanks,
 
I would
create a function put the if statement in the function
run the function from a run code action in your Autoexec macro
note the first time you open the database even if you dont log on as dba the bypass key is still true
 
thank you! I tried and tested it. It almost works perfectly....

(Just a note: under Tools, Startup, I have 'display database window' unchecked).

I login as my user called readonly without holding the shift key. The database window is correctly not shown. Then, I exit the database.

Then I login as my user called readonly again while holding the shift key. Again, the database window is correctly not shown. Then, I exit the database.

Then I login as my user called dba and hold the shift key. But it incorrectly doesn't show me the database window. It doesn't work the first time. I have to exit the database and login again as dba, then holding the shift key correctly shows the database window.

Is there a way to make holding the shift key for the dba login work every time? Is there an event that happens before autoexec?

Thanks,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top