autoExec macro headache

arage

Registered User.
Local time
Today, 20:43
Joined
Dec 30, 2000
Messages
537
autoExec macro headache
I picked up the following code from this site:

'This Code disables the shift key
'**********************************
Public Sub SetAllowByPassKeyProperty()
Dim db As Database
Dim prp As Property
Set db = CurrentDb
Set prp = db.CreateProperty("AllowByPassKey", dbBoolean, False)
db.Properties.Append prp
End Sub

It’s meant to disable the shit key when somebody logs on to access, I’ve plaec it in a standard code module & it’s called by the below function:

Public Function callAllowByPassKeyProperty()
Call SetAllowByPassKeyProperty
End Function

The above function is stored in an AUTOEXEC macro made up of a single runCode action, the callAllowByPassKeyProperty() is the only function name provided as the argument.

When I run the database I get the following run time error ‘Can’t append – an object with that name already exists in the collection – run time error 3367’
 
Code:
Public Sub SetAllowByPassKeyProperty()


Const conPropNotFoundError = 3270
'Error code to trap "Property not found"


On Error GoTo Change_Err


Dim db As Database
Dim prp As Property
Set db = CurrentDb


db.Properties("AllowByPassKey") = False


Change_Bye:
    Exit Function


Change_Err:
    If Err = conPropNotFoundError Then    ' Property not found.
        Set prp = db.CreateProperty("AllowByPassKey", _
            dbBoolean, False)
        dbs.Properties.Append prp
        Resume Next


    Else 'Unknown Error
        Resume Change_Bye
    End If


End Sub

Explanations: Originally, the AllowByPassKey property of the databse object does not exist. You have to append this property to the collection. This is what
dbs.Properties.Append prp
is meant for.

Once done, you cannot re-append (error message). The above code tries to assign the value False to the AllowByPassKey property of the Database. If it doesnt succeed, the error code is trapped. If the error is that the property had not been appended to the collection, then (and then only) it does it.

Alex

[This message has been edited by Alexandre (edited 10-16-2001).]

[This message has been edited by Alexandre (edited 10-16-2001).]
 

Users who are viewing this thread

Back
Top Bottom