Subject: Enable Shift Key to By Pass Macro!
Posted By: sampow Post Date: 12/3/2003 6:12:22 AM
I have added the following code to my project to stop users holding down the shift key to by pass the macro:

Sub SetStartupProperties()

    ChangeProperty "AllowBypassKey", dbBoolean, False

End Sub



Function ChangeProperty()

    Dim strPropName As String

    Dim varPropType As Variant

    Dim varPropValue As Variant

    

    Dim dbs As Database, prp As Property

    Const conPropNotFoundError = 3270

    strPropName = "AllowBypassKey"

    varPropType = dbBoolean

    varPropValue = False

    Set dbs = CurrentDb

    On Error GoTo Change_Err

    dbs.Properties(strPropName) = varPropValue

    ChangeProperty = True

MsgBox "Welcome to First Choice"

Change_Bye:

    Exit Function



Change_Err:

    If Err = conPropNotFoundError Then  ' Property not found.

        Set prp = dbs.CreateProperty(strPropName, varPropType, varPropValue)

        dbs.Properties.Append prp

        MsgBox "Please Try Again"

        Resume Next

    Else

        ' Unknown error.

        MsgBox "ok"

        ChangeProperty = False

        Resume Change_Bye

    End If

End Function



Now i have done that and it works fine.  Now i want to change it back so the Shift key is enabled so i can go back into the database and edit it.  I have tries changing the True/False values around but that does not work.

Can any one help me PLEASE?


Reply By: Steven Reply Date: 12/4/2003 6:46:45 PM
I think I see your problem:
You're passing variables from SetStartupProperties to ChangeProperty
The thing is, the way you've got ChangeProperty, it doesn't require variables to be passed to it.

So what you need to do is change
varPropValue = False

to
varPropValue = True

in your ChangeProperty Function.

The Sub you've got is completely pointless I must say, you could just run the ChangeProperty Function, since that's all that it does anyway.

If you DID want SetStartupProperties() to pass the variables, you'd have to change your ChangeProperty function.
It looks to me like you've copied and pasted the example from the Help file, and then messed around with it.
Paste it back, and don't mess with it, other than to change False to True.
I've pasted it here, with False changed to True just in case:

Sub SetBypassProperty()
Const DB_Boolean As Long = 1
    ChangeProperty "AllowBypassKey", DB_Boolean, True
End Sub

Function ChangeProperty(strPropName As String, varPropType As Variant, varPropValue As Variant) As Integer
    Dim dbs As Object, prp As Variant
    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


Steven


I am a loud man with a very large hat. This means I am in charge

Go to topic 7242

Return to index page 992
Return to index page 991
Return to index page 990
Return to index page 989
Return to index page 988
Return to index page 987
Return to index page 986
Return to index page 985
Return to index page 984
Return to index page 983