AllowBypassKey

  • Thread starter Thread starter DB
  • Start date Start date
D

DB

I would like to prevent users from overriding my startup
settings by pressing the shift key while opening a
database. I've been reading some of the other posts in
this Newsgroup and have found that this is done by
setting the AllowBypassKey property to false. I've seen
the code located here:

http://www.mvps.org/access/general/gen0040.htm

and I have the following code which I found in a book:

Sub KeepEmOut()
Dim db As Database
Dim pty As Property

On Error GoTo KeepEmOut_Err

Set db = CurrentDb
db.Properties("AllowBypassKey").Value = False

KeepEmOut_Exit
Exit Sub

KeepEmOut_Err:
If Err.Number = 3270 Then 'Error code for "Property
not fount"...
'so we'll create it ourselves
Set pty = db.CreateProperty("AllowBypassKey", dbBoolen,
False)
Else
MsgBox Err.Description
Resume KeepEmOut_Exit
End If
End Sub

My problem is I'm not sure how to use the code to set the
property. I've tried copying it into a module, but then
I wasn't sure how to use the module. I used the help
function in Access to lookup AllowBypassKey, but I didn't
understand the explanation it gave.

Can anyone tell me how to use the code?

Thanks in advance for any help. Please try to dumb down
any responses for me as much as possible. Thanks again.
 
Hi, thank you for responding. I ran into a problem when
following your instructions below. When I first tried to
create the MDE file, I got an error message which
said "Microsoft Access was unable to create the MDE
database". I deleted the module containing the code and
it allowed me to create the MDE file. I was thinking I
would be able to create a new module in the MDE and add
the code, but it wouldn't let me. Does Access allow an
MDE file to be created from a database with a module in
it? Did I create the module incorrectly? All I did was
create a new module and type in the KeepEmOut code and
save it. Is the code supposed to be entered somewhere in
the MDE file? Thanks for any help.
 
You're right, the code doesn't compile. When I run the
debugger the following line is highlighted:

Set pty = db.CreateProperty("AllowBypassKey", dbBoolean,
False)

and the message "Run-time error '13': Type mismatch"
appears.

It seems unusual that the code doesn't compile since I
copied it directly out of a book I have. Do you know
where the mismatch is? Thanks, I appreciate your help.
The KeepEmOut code as I currently have it is below.

Sub KeepEmOut()

Dim db As Database
Dim pty As Property

On Error GoTo KeepEmOut_Err

Set db = CurrentDb
db.Properties("AllowBypassKey").Value = False

KeepEmOut_Exit:
Exit Sub

KeepEmOut_Err:
If Err.Number = 3270 Then 'Error code
for "Property not found"...
'so we'll create it ourselves
Set pty = db.CreateProperty("AllowBypassKey",
dbBoolean, False)
db.Properties.Append pty
Else
MsgBox Err.Description
Resume KeepEmOut_Exit
End If

End Sub
 
Back
Top