O
OssieMac
Not sure if I should place this question under Security or Programming.
I am using the following code (posted below) directly out of the downloaded
MS Access Security FAQ.doc. (Well the function is but the code in the sub
invoking the function is my code.)
When I compile I get errors on the following 2 lines dimensioning variables.
Dim ws As Workspace
Dim db As DATABASE
Compile error:
User-defined type not defined.
You will see in the code below that I have commented out the As Workspace
and As DATABASE and the code runs and under exhaustive testing, it appears to
do what it should.
It appears that I should be setting a reference or something but I haven't a
clue as to what I should do so any help will be greatly appreciated.
One might ask why I bother if it works but I am still quite new to this
Access programming and knowing the answer it might help in the future.
Option Compare Database
Option Explicit
Sub SetShiftKeyBypass()
Dim strDBName As String
Dim fAllow As Boolean
Dim mySetBypass
strDBName = CurrentDb.Name
fAllow = True
mySetBypass = faq_DisableShiftKeyBypass(strDBName, fAllow)
MsgBox "DisableShiftKeyBypass set to: " & mySetBypass
End Sub
Function faq_DisableShiftKeyBypass(strDBName As String, fAllow As Boolean)
As Boolean
On Error GoTo errDisableShift
Dim ws 'As Workspace
Dim db 'As DATABASE
Dim dbBoolean
Dim prop As Property
Const conPropNotFound = 3270
Set ws = DBEngine.Workspaces(0)
Set db = ws.OpenDatabase(strDBName)
db.Properties("AllowByPassKey") = Not fAllow
faq_DisableShiftKeyBypass = fAllow
exitDisableShift:
Exit Function
errDisableShift:
'The AllowBypassKey property is a user-defined
' property of the database that must be created
' before it can be set. This error code will execute
' the first time this function is run in a database.
If Err = conPropNotFound Then
' You must set the fourth DDL parameter to True
' to ensure that only administrators
' can modify it later. If it was created wrongly, then
' delete it and re-create it correctly.
Set prop = db.CreateProperty("AllowByPassKey", _
dbBoolean, False, True)
db.Properties.Append prop
Resume
Else
MsgBox "Function DisableShiftKeyBypass did not complete successfully."
faq_DisableShiftKeyBypass = False
GoTo exitDisableShift
End If
End Function
I am using the following code (posted below) directly out of the downloaded
MS Access Security FAQ.doc. (Well the function is but the code in the sub
invoking the function is my code.)
When I compile I get errors on the following 2 lines dimensioning variables.
Dim ws As Workspace
Dim db As DATABASE
Compile error:
User-defined type not defined.
You will see in the code below that I have commented out the As Workspace
and As DATABASE and the code runs and under exhaustive testing, it appears to
do what it should.
It appears that I should be setting a reference or something but I haven't a
clue as to what I should do so any help will be greatly appreciated.
One might ask why I bother if it works but I am still quite new to this
Access programming and knowing the answer it might help in the future.
Option Compare Database
Option Explicit
Sub SetShiftKeyBypass()
Dim strDBName As String
Dim fAllow As Boolean
Dim mySetBypass
strDBName = CurrentDb.Name
fAllow = True
mySetBypass = faq_DisableShiftKeyBypass(strDBName, fAllow)
MsgBox "DisableShiftKeyBypass set to: " & mySetBypass
End Sub
Function faq_DisableShiftKeyBypass(strDBName As String, fAllow As Boolean)
As Boolean
On Error GoTo errDisableShift
Dim ws 'As Workspace
Dim db 'As DATABASE
Dim dbBoolean
Dim prop As Property
Const conPropNotFound = 3270
Set ws = DBEngine.Workspaces(0)
Set db = ws.OpenDatabase(strDBName)
db.Properties("AllowByPassKey") = Not fAllow
faq_DisableShiftKeyBypass = fAllow
exitDisableShift:
Exit Function
errDisableShift:
'The AllowBypassKey property is a user-defined
' property of the database that must be created
' before it can be set. This error code will execute
' the first time this function is run in a database.
If Err = conPropNotFound Then
' You must set the fourth DDL parameter to True
' to ensure that only administrators
' can modify it later. If it was created wrongly, then
' delete it and re-create it correctly.
Set prop = db.CreateProperty("AllowByPassKey", _
dbBoolean, False, True)
db.Properties.Append prop
Resume
Else
MsgBox "Function DisableShiftKeyBypass did not complete successfully."
faq_DisableShiftKeyBypass = False
GoTo exitDisableShift
End If
End Function