p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

access thread: AllowBypassKey woes...


Message #1 by kennyalligood@h... on Sun, 9 Jun 2002 00:22:18
Hello folks - I need a bit of help from you. I am trying to secure a 
database by restricting access via the Shift key. By setting the 
AllowBypassKey to false this should solve the problem but for some reason 
I just can't get it right.

I am new to this aspect of Access and have modeled my code from others but 
every time that I run the code I get 'Complie Error: user-defined type not 
defined'. The Type in question is -Dim db as Database- and of course -Set 
db = CurrentDb()- gives me the same problems.

How can I get this done so the function will work? I really appreciate any 
help that you can offer.....

Kenny Alligood
Message #2 by elizabeth_mohr@f... on Mon, 10 Jun 2002 16:07:14
> Hello folks - I need a bit of help from you. I am trying to secure a 
d> atabase by restricting access via the Shift key. By setting the 
A> llowBypassKey to false this should solve the problem but for some 
reason 
I>  just can't get it right.

> I am new to this aspect of Access and have modeled my code from others 
but 
e> very time that I run the code I get 'Complie Error: user-defined type 
not 
d> efined'. The Type in question is -Dim db as Database- and of course -
Set 
d> b = CurrentDb()- gives me the same problems.

> How can I get this done so the function will work? I really appreciate 
any 
h> elp that you can offer.....

> Kenny Alligood
Message #3 by "Amy Wyatt" <amyw@c...> on Mon, 10 Jun 2002 16:10:58
Check to make sure you have the DAO referances selected. They are not 
selected by default in Access 2000 + so you have to select them manually. 
Also, you will then want to change your dim to Dim db as DAO.Database so 
that Access 2000 + does not confuse it with ADO referances.

Hope this helps,

Amy

> Hello folks - I need a bit of help from you. I am trying to secure a 
d> atabase by restricting access via the Shift key. By setting the 
A> llowBypassKey to false this should solve the problem but for some 
reason 
I>  just can't get it right.

> I am new to this aspect of Access and have modeled my code from others 
but 
e> very time that I run the code I get 'Complie Error: user-defined type 
not 
d> efined'. The Type in question is -Dim db as Database- and of course -
Set 
d> b = CurrentDb()- gives me the same problems.

> How can I get this done so the function will work? I really appreciate 
any 
h> elp that you can offer.....

> Kenny Alligood
Message #4 by elizabeth_mohr@f... on Mon, 10 Jun 2002 16:11:57
sorry about that last reply.  i'm a little foggy this morning.

anyway, i think you just need to go into your module, click Tools, then 
References on the toolbar.  Make sure that Microsoft DAO 3.6 Object 
Library is selected.  Click OK and then try again.  If that still doesn't 
do the trick, sometimes I have to go back in and move the Microsoft DAO 
3.6 OL up the list.  You can do that in the Tools - References dialog box 
as well.

Hope that helps.
Message #5 by braxis@b... on Mon, 10 Jun 2002 17:34:09 +0100 (BST)
The equivalent in an ADO database is to set the AllowByPassKey custom connection property. Here's some
code that'll do it:

Public Function AddCustomConnectionProperty(strPropName As String, varPropValue As Variant) As Boolean
' Add custom properties to the AccessObjectProperties
' collection that is associated with an AccessObject object.
Const conPropNotFoundError = 3265
On Error GoTo AddProp_Err

    With CurrentProject
        .Properties(strPropName) = varPropValue
    End With
    AddCustomConnectionProperty = True
AddProp_Bye:
    Exit Function

AddProp_Err:
    If Err = conPropNotFoundError Or Err = 2455 Then
    With CurrentProject.Properties
        .Add strPropName, varPropValue
    End With
    Resume
    Else
        MsgBox Err.Description
        AddCustomConnectionProperty = False
        Resume AddProp_Bye
    End If

End Function


To totally secure my database I run the following code - make sure you have a spare copy of the database before using this, as
you'll never get into the database again!

Public Function SecureDatabase()
    
    AddCustomConnectionProperty "AllowBypassKey", False
    AddCustomConnectionProperty "AllowBreakIntoCode", False
    AddCustomConnectionProperty "StartupShowDBWindow", False
    AddCustomConnectionProperty "StartupShowStatusBar", True
    AddCustomConnectionProperty "AllowBuiltinToolbars", False
    AddCustomConnectionProperty "AllowShortcutMenus", False
    AddCustomConnectionProperty "AllowBuiltInToolbars", False
    AddCustomConnectionProperty "AllowFullMenus", False
    AddCustomConnectionProperty "AllowToolbarChanges", False
    AddCustomConnectionProperty "AllowSpecialKeys", False
    
End Function


Brian
>  from:    elizabeth_mohr@f...
>  date:    Mon, 10 Jun 2002 17:07:14
>  to:      access@p...
>  subject: Re: [access] Re: AllowBypassKey woes...
> 
> > Hello folks - I need a bit of help from you. I am trying to secure a 
> d> atabase by restricting access via the Shift key. By setting the 
> A> llowBypassKey to false this should solve the problem but for some 
> reason 
> I>  just can't get it right.
> 
> > I am new to this aspect of Access and have modeled my code from others 
> but 
> e> very time that I run the code I get 'Complie Error: user-defined type 
> not 
> d> efined'. The Type in question is -Dim db as Database- and of course -
> Set 
> d> b = CurrentDb()- gives me the same problems.
> 
> > How can I get this done so the function will work? I really appreciate 
> any 
> h> elp that you can offer.....
> 
> > Kenny Alligood

Message #6 by kennyalligood@h... on Thu, 13 Jun 2002 02:49:29
I would like to thank everyone that added a reply to help me thru my 
difficult situation but the following code is what I actually got to work.

I added a macro to run the LockDB() OnLoad and a Form with a Command 
button that activated the UnLockDB() after password authentication.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function LockDB() As Boolean
On Error GoTo LockDB_Err

Const DB_Text As Long 
Const DB_Boolean As Long

Call ChangeProperty("StartupShowDBWindow", DB_Boolean, False)
Call ChangeProperty("StartupShowStatusBar", DB_Boolean, True)
Call ChangeProperty("AllowBuiltinToolbars", DB_Boolean, False)
Call ChangeProperty("AllowFullMenus", DB_Boolean, False)
Call ChangeProperty("AllowBreakIntoCode", DB_Boolean, False)
Call ChangeProperty("AllowSpecialKeys", DB_Boolean, False)
Call ChangeProperty("AllowBypassKey", DB_Boolean, False)
Call ChangeProperty("AllowShortcutMenus", DB_Boolean, False)
Call ChangeProperty("AllowToolbarChanges", DB_Boolean, False)

LockDB = True

LockDB_Exit:
Exit Function

LockDB_Err:
MsgBox Err.Description
Resume LockDB_Exit

End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function UnLockDb() As Boolean
On Error GoTo UnLockDB_Err

Const DB_Text As Long 
Const DB_Boolean As Long

Call ChangeProperty("StartUpShowDBWindow", DB_Boolean, True)
Call ChangeProperty("StartupShowStatusBar", DB_Boolean, True)
Call ChangeProperty("AllowBuiltInToolbars", DB_Boolean, True)
Call ChangeProperty("AllowFullMenus", DB_Boolean, True)
Call ChangeProperty("AllowBreakIntoCode", DB_Boolean, True)
Call ChangeProperty("AllowSpecialKeys", DB_Boolean, True)
Call ChangeProperty("AllowBypassKey", DB_Boolean, True)
Call ChangeProperty("AllowToolbarChanges", DB_Boolean, True)
Call ChangeProperty("AllowShortcutMenus", DB_Boolean, True)

UnLockDb = True

UnLockDb_Exit:
Exit Function

UnLockDb_Err:
MsgBox Err.Description
Resume UnLockDb_Exit

End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function ChangeProperty(strProperty As String, varType As Variant, 
varValue As Variant) As Integer
On Error GoTo ChangeProperty_Err

Dim db As Object
Dim prp As Variant
Const PropertyNotfound = 3270

Set db = CurrentDb
On Error GoTo ChangeProperty_Err

db.Properties(strProperty) = varValue
ChangeProperty = True

ChangeProperty_Exit:
On Error Resume Next
Set db = Nothing
Err = 0
On Error GoTo 0
Exit Function

ChangeProperty_Err:
If Err = PropertyNotfound Then ' Property not found.
    Set prp = db.CreateProperty(strProperty, varType, varValue)
    db.Properties.Append prp
    Resume Next
Else
    MsgBox Err.Description
End IF

End Function

  Return to Index