Link to home
Start Free TrialLog in
Avatar of wiswalld
wiswalldFlag for United States of America

asked on

Disable shift key on start up

Disable shift key on startup and prompt for password. I have used the code from the following link but get a syntax error on the msgbox part.

http://www.databasedev.co.uk/disable_shift_bypass.html
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

For reference:

Sub SetBypassProperty()
Const DB_Boolean As Long = 1
    ChangeProperty "AllowBypassKey", DB_Boolean, False
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 = dbEngine.Workspaces(0).Opendatabase(<path>)
    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
     

Then call from the debug window with:

SetBypassProperty

  This will turn the shift key bypass off in the MDB.  Close this MDB and open the other holding down the shift key.  You should get the normal toolbars and the database container.

------------

mx
What is the error and can you paste your exact code ...

mx
which part? paste it here
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
take your pick

MsgBox "The Bypass Key has been enabled." & vbCrLf & vbLf & _
               "The Shift key will allow the users to bypass the startup " & _
               "options the next time the database is opened.", _
               vbInformation, "Set Startup Properties"

        MsgBox "Incorrect ''AllowBypassKey'' Password!" & vbCrLf & vbLf & _
               "The Bypass Key was disabled." & vbCrLf & vbLf & _
               "The Shift key will NOT allow the users to bypass the " & _
               "startup options the next time the database is opened.", _
               vbCritical, "Invalid Password"

Avatar of wiswalld

ASKER

Compile Error:

Syntax error on the message portions you highlighted.
The code compiles on my system ...

maybe  do this:

A **DeCompile** may help here ...

But first, if you have not already:
Check for any **Missing References via the VBA Editor>>Tools>>References ....

Then, follow this procedure:

0) **Backup your MDB**
1) Compact and Repair
2) Execute the Decompile (See below) >> your database will reopen
3) Close the mdb
4) Open the mdb and do a Compact and Repair from the
5) Open the mdb:
    a) Right click over a 'blank' area of the database window (container) and select Visual Basic Editor. A new window will open with the title 'Microsoft Visual Basic' ... followed by then name of your MDB.
    b) From the VBA Editor Menu at the top of the window:
       >>Debug>>Compile
        Note ... after the word Compile ...you will see the name of your 'Project' - just an fyi.

6) Close the mdb
7) Compact and Repair one more time.

*** Executing the DeCompile:
Here is an example of the command line syntax  (adjust your path and file name accordingly) for executing the

decompile:

Run this from Start>>Run, enter the following command line ...

"C:\Program Files\Microsoft Office\Office\Msaccess.exe" /decompile

"C:\Access2003Clients\AzDoc\Pgrm\AzDocPgrm2K3.mdb"

For more detail on the Decompile subject ... visit the Master on the subject (and other great stuff) Michael Kaplan:

http://www.trigeminal.com/usenet/usenet004.asp?1033

mx
Module:

Option Compare Database
Option Explicit

Public Function SetProperties(strPropName As String, _
varPropType As Variant, varPropValue As Variant) As Integer

    On Error GoTo Err_SetProperties

    Dim db As DAO.Database, prp As DAO.Property

    Set db = CurrentDb
    db.Properties(strPropName) = varPropValue
    SetProperties = True
    Set db = Nothing

Exit_SetProperties:
    Exit Function

Err_SetProperties:
    If Err = 3270 Then    'Property not found
        Set prp = db.CreateProperty(strPropName, varPropType, varPropValue)
        db.Properties.Append prp
        Resume Next
    Else
        SetProperties = False
        MsgBox "SetProperties", Err.Number, Err.Description
        Resume Exit_SetProperties
    End If
End Function


Private Sub bDisableBypassKey_Click()
    On Error GoTo Err_bDisableBypassKey_Click
    'This ensures the user is the programmer needing to disable the Bypass Key
    Dim strInput As String
    Dim strMsg As String
    Beep
    strMsg = "Do you want to enable the Bypass Key?" & vbCrLf & vbLf & _
             "Please key the programmer's password to enable the Bypass Key."
    strInput = InputBox(Prompt:=strMsg, title:="Disable Bypass Key Password")
    If strInput = "TypeYourBypassPasswordHere" Then
        SetProperties "AllowBypassKey", dbBoolean, True
        Beep
        MsgBox "The Bypass Key has been enabled." & vbCrLf & vbLf & _
               "The Shift key will allow the users to bypass the startup & _
               options the next time the database is opened.", _
               vbInformation, "Set Startup Properties"
    Else
        Beep
        SetProperties "AllowBypassKey", dbBoolean, False
        MsgBox "Incorrect ''AllowBypassKey'' Password!" & vbCrLf & vbLf & _
               "The Bypass Key was disabled." & vbCrLf & vbLf & _
               "The Shift key will NOT allow the users to bypass the & _
               startup options the next time the database is opened.", _
               vbCritical, "Invalid Password"
        Exit Sub
    End If
Exit_bDisableBypassKey_Click:
    Exit Sub
Err_bDisableBypassKey_Click:
    MsgBox "bDisableBypassKey_Click", Err.Number, Err.Description
    Resume Exit_bDisableBypassKey_Click
End Sub

When I compile it hangs on this

        MsgBox "The Bypass Key has been enabled." & vbCrLf & vbLf & _
               "The Shift key will allow the users to bypass the startup & _
               options the next time the database is opened.", _
               vbInformation, "Set Startup Properties"
Followed this:

You might have to set your "References" in the VBA editor to DAO 3.6.

When you are viewing a Module, click the Tools menu » References. Browse for Microsoft DAO 3.6

Select "Files of type: Executable Files (*.exe; *.dll)"

C:\Program Files\Common Files\Microsoft Shared\DAO)

Then explicitly dimension yourcode, i.e. Dim db As DAO.Database, prp As DAO.Property

I get to the part where it opens the DAO file with three things in it. Should I be selecting one?
What does this line mean:

Then explicitly dimension yourcode, i.e. Dim db As DAO.Database, prp As DAO.Property

What does this line mean:
Then explicitly dimension yourcode, i.e. Dim db As DAO.Database, prp As DAO.Property

I means ...instead of doing  Dim db As Database, prp As Property

You specifically indicate that you are using DAO ... instead of ADO ...because ... it is possible to use both.

mx
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
both this compiles in here, try copy and paste

MsgBox "The Bypass Key has been enabled." & vbCrLf & vbLf & _
               "The Shift key will allow the users to bypass the startup " & _
               "options the next time the database is opened.", _
               vbInformation, "Set Startup Properties"

        MsgBox "Incorrect ''AllowBypassKey'' Password!" & vbCrLf & vbLf & _
               "The Bypass Key was disabled." & vbCrLf & vbLf & _
               "The Shift key will NOT allow the users to bypass the " & _
               "startup options the next time the database is opened.", _
               vbCritical, "Invalid Password"
Same problem here

MsgBox "Incorrect ''AllowBypassKey'' Password!" & vbCrLf & vbLf & _
               "The Bypass Key was disabled." & vbCrLf & vbLf & _
               "The Shift key will NOT allow the users to bypass the & _
               startup options the next time the database is opened.", _
               vbCritical, "Invalid Password"
mx, i posted that already above
fyi
"what does this line mean:
Then explicitly dimension yourcode, i.e. Dim db As DAO.Database, prp As DAO.Property"

If you are only using DAO ... then you do not need to add the DAO prefix ... BUT ... for clarity ... and in case you do add ADO later ... best practice these days is to explicitly include the DAO prefix ... easy to do ... and it will eliminate confusion later.

mx
wiswalld,
that is not the same as the one i posted....
Sorry Capricorn doing three things at once. The code I posted was the original code from the website. Real stupid question though: what is the passowrd going to be?
cap ... sorry ... I was looking at what he posted ... tested it ... saw the error ... fixed it .. and posted it.

mx
the password is set here

 If strInput = "TypeYourBypassPasswordHere" Then


replace { TypeYourBypassPasswordHere } with your password
Thanks