Log in

View Full Version : Solved: Bypass Mode in Access



kbsudhir
08-12-2009, 10:44 AM
Hi All,

I read the thread by Oorang.

http://vbaexpress.com/forum/showthread.php?t=26204

There is no doubt that its an excellent piece of code. Which in fact put complete thought process into motion.


we can ensure that nobody can change the data in tables/queries/design etc

By making "Login" System in the access application.
Entering the startup options & disabling the menus.
We can even disable the bypass option which is Press "Shift" key while opening the database.In my case I am using the 2nd options as there are macros running which are updating my data in the tables & if I want to change to option one a lot of work has to be put in hence not feasible as of now.

Lets go to option 3. If I disable the bypass option, then as a developer how can I enter the design mode to update various stuff.

Hence if there a way we can disable the bypass key & still able to enter the database & make changes..!!!!!!!!!!!!

Or is there any way the access will check the usee credentials without asking for login & exit if the person is in bypass mode even before he/she chnages anything.

I work in citric hence can use VBA.Environ("Username") get the name of teh user without even asking him/her to login.


Any Ideas/guidance is invaluable as always.

Regards
Sudhir

CreganTur
08-12-2009, 11:29 AM
You could always use this:

When bypass mode is detected, launch a login form that asks for username and password. Only the developer will know what to enter. If you're not the developer, the application is closed. If you are the developer, you allow bypass mode to open as normal.

kbsudhir
08-12-2009, 11:50 AM
But how to detect the bypass...???

OBP
08-13-2009, 03:23 AM
See these threads
http://support.microsoft.com/kb/826765
http://www.databasedev.co.uk/disable_shift_bypass.html

kbsudhir
08-14-2009, 02:51 AM
Thanks OBP for the guidance.

I am inserting my codes below:

Add the below code in a module.

Option Compare Database
Option Explicit
Public Function SetProperties(strPropName As String, _
varPropType As Variant, varPropValue As Variant) As Integer
On Error GoTo Err_SetProperties
Dim db As DAO.Database, prp As DAO.Property
Set db = CurrentDb
db.Properties(strPropName) = varPropValue
SetProperties = True
Set db = Nothing
Exit_SetProperties:
Exit Function
Err_SetProperties:
If Err = 3270 Then 'Property not found
Set prp = db.CreateProperty(strPropName, varPropType, varPropValue)
db.Properties.Append prp
Resume Next
Else
SetProperties = False
MsgBox "SetProperties", Err.Number, Err.Description
Resume Exit_SetProperties
End If
End Function



Now, You can call this from any button click.


Private Sub Dev_btn_Click()
If IsNull(Me.UsrTxt) = True Or IsNull(Me.PassTxt) = True Then
MsgBox "Please Enter UserName & Password", vbInformation, "Missing Info"
Exit Sub
End If

If Me.UsrTxt <> "Administrator" And Me.PassTxt <> "Access4Bypass" Then

MsgBox "Either Role or Password is wrong", vbCritical, "Please Verify"
Exit Sub
End If

On Error GoTo Err_Develop_Btn_Click

Dim strInput As String
Dim strMsg As String
Beep


If Me.cboBypass.Value = "Allow Bypass" Then

SetProperties "AllowBypassKey", dbBoolean, True

MsgBox "The Bypass Key has been enabled." & vbCrLf & vbLf & _
"The Shift key will allow the users to bypass the startup" & _
" options the next time the database is opened.", _
vbInformation, "Set Startup Properties"
Exit Sub

End If

If Me.cboBypass.Value = "Disable Bypass" Then


SetProperties "AllowBypassKey", dbBoolean, False


MsgBox "The Bypass Key has been disabled." & vbCrLf & vbLf & _
"The Shift key will not allow the users to bypass the startup" & _
" options the next time the database is opened.", _
vbInformation, "Set Startup Properties"

Exit Sub

End If

Exit_Develop_Btn_Click:
Exit Sub
Err_Develop_Btn_Click:
MsgBox "Develop_Btn_Click", Err.Number, Err.Description
Resume Exit_Develop_Btn_Click

End Sub


Thanks
Sudhir