Link to home
Start Free TrialLog in
Avatar of The_JFG
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...

Avatar of joekendall
joekendall
Flag of United States of America image

I believe jadedata has something that can do this. I will see if I can get his attention.

Joe
Avatar of jadedata
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=True

I never use the option myself.
Avatar of The_JFG
The_JFG

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("AllowBypassKey")
End Function

gaw
Avatar of The_JFG

ASKER

gwgaw, this looks useful, but it's not returning anything...?

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("AllowByPassKey",dbboolean,True)

 then try:
  ?CurrentDb.AllowBypassKey
 again

Tell me what happens..
Avatar of The_JFG

ASKER

Still get the error, even after a DB restart.

"Currentdb.createproperty("AllowByPassKey",dbboolean,True)" 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.  :/
What does this "?CurrentDb.AllowBypassKey" in the debug window report?
Avatar of The_JFG

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.
Avatar of The_JFG

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)?
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("AllowByPassKey",dbboolean,State)
End Sub

Joe
Avatar of The_JFG

ASKER

...

What does this actually do?

"Currentdb.createproperty("AllowByPassKey",dbboolean,True)"
It adds a Non-persistant property to the current project(db) object that can be recognized, set, changed.
Avatar of The_JFG

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("AllowByPassKey",dbboolean,State)
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.  
Avatar of The_JFG

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...

?:|

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.
Avatar of The_JFG

ASKER

Gotcha.

So, about that code... lol    :D
Public Function ChkBypass() As Boolean
 
  Dim answer As Boolean
 
  On Error GoTo ChkBypass_Err

  answer = CurrentDb.Properties("AllowBypassKey")

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
Avatar of The_JFG

ASKER

Wow -- this looks great!  

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
Avatar of The_JFG

ASKER

I did... :(
ASKER CERTIFIED SOLUTION
Avatar of jadedata
jadedata
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of The_JFG

ASKER

*** BOOM! ***

You got it!

This is one sweet little function.  Now available for all to use!

Great job!
Thank you sir!