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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function AllowBypassKey not recognized

Status
Not open for further replies.

fmientjes

Programmer
Mar 27, 2002
55
0
0
NL
I am trying to lock a database with Changeproperty AllowBypassKey, but this property is not recognized (Access 2000). I saw an existing database in which it worked!

How can I make it work?

Frans
 
Probably doesn't work because the property does not yet exist in the Db. The first time you use it you need to create the property :

Public Function disable_shift_on_entrance()
Dim prp As Property
Dim dbs As Database
Set dbs = CurrentDb
dbs.Properties("AllowByPassKey") = False
Set prp = dbs.CreateProperty("AllowByPassKey", _
dbBoolean, False)
dbs.Properties.Append prp
End Function

After that, you can use :
dbCurrent.Properties("AllowBypassKey") = True
(or False offcourse)

Just make sure you don't lock yourself out.


"In three words I can sum up everything I've learned about life: it goes on."
- Robert Frost 1874-1963
 
This is just a variation on the same...

I handle the Properties.Append in the error handler if the property doesn't exist yet. The message box will tell you what the setting is.

I call this routine from some small label on the double_click event. Then I can set the ByPass on or off quickly and know what the setting is immediately.

[tt]

Private Const PropNotFound As Long = 3270


Public Sub ByPassKeyToggle()
'This Code Disables/Enables the Shift Key
On Error GoTo Error_ByPass

Dim Prp As DAO.Property
Dim db As DAO.Database
Dim blnToggle As Boolean

Set db = CurrentDb()
blnToggle = db.Properties("allowbypasskey")

blnToggle = Not blnToggle

db.Properties("AllowByPassKey") = blnToggle

blnToggle = db.Properties("AllowByPassKey")

MsgBox "AllowByPass is set to " & blnToggle

Error_ByPass:
If PropNotFound Then

Set Prp = db.CreateProperty("AllowByPassKey", dbBoolean, True)
db.Properties.Append Prp
db.Properties.Refresh

Resume Next



Else

MsgBox "Bypass routine failed due to " & Err.Number & ": " & Err.Description

End If

Exit Sub

End Sub
[/tt]
 
Thanks for your examples.
Unfortunately it doesn't work :-( . Error message 3270: cannot find property.
The same goes for property AllowBreakIntoCode
Any more suggestions?

Thanks,
Frans
 
I had a similar problem using this code, where access would present a message box basically saying the property already existed in the collection.

after commenting the following line, everything worked well.

db.Properties.Append Prp

Great piece of code guys, and thanks for sharing :)

I was just wondering though, how do you utliise it? At present i also run the code from the double-click event of a hidden label at the top-left hand corner of the first form shown in the database.

Is there any way to check if another key is pressed at the same time?

Ideally I'd like for this code to only be run if the control key is held down at the same time as double-clicking the hidden label, any ideas?

 
fmientjes:

Did you declare the constant that refers to Error 3370?

Do you have the code editor (Tools > Options > General ) set to "Break on all errors" ? This would circumvent the handling of the error.
 
Dear Quehay,

Still get the message: Error 3270: Cannot find property.
I treid the other code as wll.

It seems tom e that Access is not able to append this property. Is this a bug in Access 2000?
Help is really appreciated.

Thanks,
Frans
 
This is not a bug in Access. The code supplied by DaOtH should work - I use the same principle in my databases.

e.g.

Dim Dbs As Database
Dim prpNew as Property

Set Dbs = CurrentDb
Set prpNew = Dbs.CreateProperty("AllowBypassKey", dbBoolean, False)
NewDB.Properties.Append prpNew

Have fun! :eek:)

Alex Middleton
 
*You'll notice that this (DaOtH cited above) is the very code that's in the error handler, with the addition of a .Refresh. The advantage is that this can be dropped into a new db and run without manually creating the property; once created the sub won't attempt to recreate it.

Try putting a breakpoint early in the sub and stepping through the routine--see if it drops into the error handler and responds properly to the test for the constant. (Did you make sure that code is set to break only on unhandled errors?)
 
Finally, I got it working.
I manually created the property first, because none of the code above worked. (error number 0:)
A reference to MS DAO 3.6 had to be made too.
It bothers me that it should work with an error bypass, but in the end it works.

Thanks for your help [2thumbsup].

Frans
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top