The_JFG
asked on
Detect AllowBypassKey State
Is there a way to detect the state of the AllowBypassKey?
I would like to be able to call a small function and have it return the result.
If DetectBypass = True then...
I would like to be able to call a small function and have it return the result.
If DetectBypass = True then...
Joe caught me napping.... :)
The AllowBypassKey is not a persistant property of the DB Project so you have to be careful looking for it's value, and expect as error if the DB designer has never set it before. You will get "Member or Data Object Not Found" if the property has not been appended to the Database Object
Write your code with a special error trap to detect for this error (by number)
The error condition equates to:
currentdb.AllowBypassKey=T rue
I never use the option myself.
The AllowBypassKey is not a persistant property of the DB Project so you have to be careful looking for it's value, and expect as error if the DB designer has never set it before. You will get "Member or Data Object Not Found" if the property has not been appended to the Database Object
Write your code with a special error trap to detect for this error (by number)
The error condition equates to:
currentdb.AllowBypassKey=T
I never use the option myself.
ASKER
Interesting...
There are many properties of the DB object that must be used once before they are appended to the object, or you must code them into place. Application Window caption for another one.
The following function will return false if the AllowByPassKey property doesn't exist or it does exists and is set to false. Otherwise it will return true.
Public Function GetAllowBypassKey() As Boolean
On Error Resume Next
GetAllowBypassKey = CurrentDb.Properties("Allo wBypassKey ")
End Function
gaw
Public Function GetAllowBypassKey() As Boolean
On Error Resume Next
GetAllowBypassKey = CurrentDb.Properties("Allo
End Function
gaw
ASKER
gwgaw, this looks useful, but it's not returning anything...?
Your thoughts?
Your thoughts?
Try doing this in the debug window (ctrl-G to access it)
?CurrentDb.AllowBypassKey
If you get an error the property has not been set yet.
Then put
Currentdb.createproperty(" AllowByPas sKey",dbbo olean,True )
then try:
?CurrentDb.AllowBypassKey
again
Tell me what happens..
?CurrentDb.AllowBypassKey
If you get an error the property has not been set yet.
Then put
Currentdb.createproperty("
then try:
?CurrentDb.AllowBypassKey
again
Tell me what happens..
ASKER
Still get the error, even after a DB restart.
"Currentdb.createproperty( "AllowByPa ssKey",dbb oolean,Tru e)" returns True.
I've already incorporated the enable / disable call functionality (found here: https://www.experts-exchange.com/questions/20602857/Access2000-AllowBypassKey.html -- the one directly below the accepted answer).
So, it's working (the disable bypasskey).... but this doesn't seem to be. :/
"Currentdb.createproperty(
I've already incorporated the enable / disable call functionality (found here: https://www.experts-exchange.com/questions/20602857/Access2000-AllowBypassKey.html -- the one directly below the accepted answer).
So, it's working (the disable bypasskey).... but this doesn't seem to be. :/
What does this "?CurrentDb.AllowBypassKey " in the debug window report?
ASKER
"Member or Data Object Not Found"
This is why I was saying to write the code with that error trap in it specifically.
This is frankly a normal behaviour for Access.
This is frankly a normal behaviour for Access.
ASKER
Indeed.
OK, so what needs to be tweaked from gwgaw's post so that I can get this workin' (I wasn't getting ANY response from his code above)?
OK, so what needs to be tweaked from gwgaw's post so that I can get this workin' (I wasn't getting ANY response from his code above)?
Combine what gwgaw has given you and this to do what you need.
If GetAllowBypassKey = False Then
AllowByPassKey True
End If
Public Sub AllowByPassKey(ByVal State As Boolean)
Currentdb.createproperty(" AllowByPas sKey",dbbo olean,Stat e)
End Sub
Joe
If GetAllowBypassKey = False Then
AllowByPassKey True
End If
Public Sub AllowByPassKey(ByVal State As Boolean)
Currentdb.createproperty("
End Sub
Joe
ASKER
...
What does this actually do?
"Currentdb.createproperty( "AllowByPa ssKey",dbb oolean,Tru e)"
What does this actually do?
"Currentdb.createproperty(
It adds a Non-persistant property to the current project(db) object that can be recognized, set, changed.
ASKER
*----- In some Form -----*
Private Sub Button_Check_Click()
If AllowByPassKey = True Then
msgbox "The DB is not secured"
Else
msgbox "The DB is locked down"
End If
End Sub
*-------------------------
*----- In some Module -----*
Function AllowByPassKey(ByVal State As Boolean)
AllowByPassKey = Currentdb.createproperty("
End Function
*-------------------------
I just need some help with the module part. Most of this makes sense, I'm just waiting for that lightbulb!
Both function DO essentially the same thing,... they manipulate the AllByPassKey property.
ASKER
Do I really want to manipulate the property? I don't want to turn it off and on with this function -- rather query the current state that it's in.
In the example above, there is a button click even that runs a function in a module somewhere. The results of that function determine the type of message box that pops up.
I guess I'm not grasping the exact syntax needed to complete the AllowByPassKey function to return a simple True or False if the shift key is disabled or not...
?:|
In the example above, there is a button click even that runs a function in a module somewhere. The results of that function determine the type of message box that pops up.
I guess I'm not grasping the exact syntax needed to complete the AllowByPassKey function to return a simple True or False if the shift key is disabled or not...
?:|
The problem is that is this particular property actually has three states
True = True
False = False
Nonexistant = False
The code needs to take that third possibility into account.
True = True
False = False
Nonexistant = False
The code needs to take that third possibility into account.
ASKER
Gotcha.
So, about that code... lol :D
So, about that code... lol :D
Public Function ChkBypass() As Boolean
Dim answer As Boolean
On Error GoTo ChkBypass_Err
answer = CurrentDb.Properties("Allo wBypassKey ")
ChkBypass_Exit:
Exit Function
ChkBypass_Err:
Select Case Err
Case 3270
Resume ChkBypass_Exit
Case Else
MsgBox Error$ & vbTab & Err
Resume ChkBypass_Exit
Resume
End Select
End Function
Dim answer As Boolean
On Error GoTo ChkBypass_Err
answer = CurrentDb.Properties("Allo
ChkBypass_Exit:
Exit Function
ChkBypass_Err:
Select Case Err
Case 3270
Resume ChkBypass_Exit
Case Else
MsgBox Error$ & vbTab & Err
Resume ChkBypass_Exit
Resume
End Select
End Function
ASKER
Wow -- this looks great!
Hummm, seems to always return False when I'm testing it... ?
Hummm, seems to always return False when I'm testing it... ?
Change the application setting to true:
Close the database
Reopen the database and test again
Close the database
Reopen the database and test again
ASKER
I did... :(
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
*** BOOM! ***
You got it!
This is one sweet little function. Now available for all to use!
Great job!
You got it!
This is one sweet little function. Now available for all to use!
Great job!
Thank you sir!
Joe