Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AllowBypassKey Property

Status
Not open for further replies.

Mike555

Technical User
Feb 21, 2003
1,200
0
0
US
I want to use the AllowBypassKey property to prevent users from bypassing an Autoexec macro, but I have no idea how to code this or where the code should be placed in the database. Can anyone help?

Thanks, Mike
 
Copy the following code into a global module ( including all the comments ) then read the comments and follow the instructions. Deleting all the other Properties that you do not want to change.


Code:
'# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #'
'                                                                                   '
' Copy the following into the calling database's StartUp Form                       '
' Private Sub Form_Open()                                                           '
'   If CurrentUser() = "Developer" Then                                             '
'       If MsgBox("Change Startup property settings ?", vbYesNo ) = vbYes Then      '
'           Call SetStartupProperties()                                             '
'       End If                                                                      '
'   End If                                                                          '
' End Sub                                                                           '
'                                                                                   '
' Private Sub SetStartupProperties()                                                '
'    Const dbText As Long = 10                                                      '
'    Const dbBoolean As Long = 1                                                    '
'    Dim dbs As Object                                                              '
'    Set dbs = CurrentDb                                                            '
'    ChangeProperty "StartupForm", dbText, "frmStartUp", dbs                        '
'    ChangeProperty "StartupShowDBWindow", dbBoolean, True, dbs   ' False           '
'    ChangeProperty "StartupShowStatusBar", dbBoolean, True, dbs                    '
'    ChangeProperty "AllowBuiltinToolbars", dbBoolean, True, dbs  ' False           '
'    ChangeProperty "AllowFullMenus", dbBoolean, True, dbs        ' False           '
'    ChangeProperty "AllowBreakIntoCode", dbBoolean, True, dbs    ' False           '
'    ChangeProperty "AllowSpecialKeys", dbBoolean, True, dbs                        '
'    ChangeProperty "AllowBypassKey", dbBoolean, True, dbs        ' False           '
'    MsgBox "DB Properties Have Been Set for developer use .. ."                    '
' End Sub                                                                           '
'                                                                                   '
' Then in a Sub that will always runs when the database closes down                 '
'       ( EG. frmMainMenu.Close )                                                   '
'                                                                                   '
' Private Sub Form_Close()                                                          '
'   If CurrentUser() = "Developer" Then                                             '
'       If MsgBox("Secure database using Startup property settings ?", vbYesNo ) _  '
'                                                                   = vbYes Then    '
'           Call ReSetStartupProperties()                                           '
'       End If                                                                      '
'   End If                                                                          '
' End Sub                                                                           '
'                                                                                   '
' Private Sub ReSetStartupProperties()                                              '
'    Const dbText As Long = 10                                                      '
'    Const dbBoolean As Long = 1                                                    '
'    Dim dbs As Object                                                              '
'    Set dbs = CurrentDb                                                            '
'    ChangeProperty "StartupForm", dbText, "frmStartUp", dbs                        '
'    ChangeProperty "StartupShowDBWindow", dbBoolean, False, dbs                    '
'    ChangeProperty "StartupShowStatusBar", dbBoolean, True, dbs  'If St'Bar used in db '
'    ChangeProperty "AllowBuiltinToolbars", dbBoolean, False, dbs                   '
'    ChangeProperty "AllowFullMenus", dbBoolean, False, dbs                         '
'    ChangeProperty "AllowBreakIntoCode", dbBoolean, False, dbs                     '
'    ChangeProperty "AllowSpecialKeys", dbBoolean, False, dbs                       '
'    ChangeProperty "AllowBypassKey", dbBoolean, False, dbs                         '
'    MsgBox "DB Properties Have Been Set into secure mode .. ."                     '
' End Sub                                                                           '
'# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #'

Function ChangeProperty(strPropName As String, varPropType As Variant _
                    , varPropValue As Variant, dbs As Object) As Integer
    Dim prp As Variant
    Const conPropNotFoundError = 3270

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

Change_Exit:
    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_Exit
    End If
End Function





'ope-that-'elps.



G LS
accessaceNOJUNK@valleyalley.co.uk
Remove the NOJUNK to use.
 
OK, a question: When you say 'database's StartUp Form', do you mean the form that displays as part of the Autoexec macro? My autoexec macro contains 1 Form & 1 Report which display at startup. Are you refering to this form?

Thanks for this great info.
 
I would NEVER use a Macro - I am referring to the form that automatically opens on startup because it has been set in the Tools, StartUp..., DisplayForm/Page setting

But, yes, if you are still using macros, then the Form you call in the AutoExec macro is the one to use.




G LS
accessaceNOJUNK@valleyalley.co.uk
Remove the NOJUNK to use.
 
LittleSmudge,
I have seen recommendations both ways on setting the form through Tools->Startup vs setting the form through the AutoExec macro.

Are there any actual advantages/disadvantages to either approach, or is it simply a matter of preference?
 
It's only a matter of Macros being predicated technology that just don't get used much these days.

It's been well over 5 years now since I even looked at a macro - let alone wrote one.




G LS
accessaceNOJUNK@valleyalley.co.uk
Remove the NOJUNK to use.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top