database security

lloydmav

Registered User.
Local time
Today, 18:07
Joined
Nov 15, 2002
Messages
75
I have added some code to a transparent button to disable the shift key so that there are no shortcut ways of getting into the design view of my database. I also have a button which enables it again. See code

Private Sub Enable_Click()
Dim db As Database
Set db = CurrentDb
db.Properties.Delete "AllowByPassKey"
db.Properties.Refresh
End Sub


Private Sub Disable_Click()
Dim db As Database
Dim prp As Property
Set db = CurrentDb
Set prp = db.CreateProperty("AllowByPassKey", dbBoolean, False)
db.Properties.Append prp
End Sub

When I run the disable code I get the error "Type mismatch"

Can anyone see what I've done wrong here

Help would be really appreciated

THANKS
 
Not sure if you should be deleting properties. The code below should do what you need. Call it like so:

Private Sub Enable_Click()

ChangeProperty "AllowBypassKey", dbBoolean, false

End Sub



Function ChangeProperty(strPropName As String, varPropType As Variant, varPropValue As Variant) As Integer

Dim dbs As Database, prp As Property
Const conPropNotFoundError = 3270

Set dbs = CurrentDb
On Error GoTo Change_Err
dbs.Properties(strPropName) = varPropValue
ChangeProperty = True

Change_Bye:
Exit Function

Change_Err:
If err = conPropNotFoundError Then ' Property not found.
Set prp = dbs.CreateProperty(strPropName, varPropType, varPropValue)

dbs.Properties.Append prp
Resume Next
Else
' Unknown error.
ChangeProperty = False
Resume Change_Bye
End If
End Function
 
Ok, I've played around with it, that code great

Cheers!
 

Users who are viewing this thread

Back
Top Bottom