AllowBypassKey

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

DB

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

DB

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top