Enable/Disable Bypass Error

freidaf

Registered User.
Local time
Yesterday, 22:30
Joined
Aug 13, 2012
Messages
44
Hello,

I have the code below attached to 2 buttons on my databases Main Menu to disable/enable the bypass key. I also have a text box on the Main Menu named txtBypass that displays “True” or “False” depending on if the bypass is enabled or not. I recently converted this database from Access 2010 to Access 2013 and began getting the error “Property not found.” Can anyone tell me why? I have attached a doc with the code below and picture of the Main Menu.
Thank you for your help.

Disable Button Code
Private Sub cmdDisable_Click()
On Error Resume Next
Dim DB As DAO.Database
Dim PR As DAO.Property
Set DB = CurrentDb
Set PR = DB.CreateProperty("AllowBypassKey", dbBoolean, False)
DB.Properties.Append PR
DB.Properties("AllowBypassKey") = False
Set PR = DB.CreateProperty("AllowSpecialKeys", dbBoolean, False)
DB.Properties.Append PR
DB.Properties("AllowSpecialKeys") = False
Set PR = DB.CreateProperty("AllowFullMenus", dbBoolean, False)
DB.Properties.Append PR
DB.Properties("AllowFullMenus") = False
Set PR = DB.CreateProperty("AllowDefaultShortcutMenus", dbBoolean, False)
DB.Properties.Append PR
DB.Properties("AllowDefaultShortcutMenus") = False
Set DB = Nothing
MsgBox "Bypass Key Disabled"
End Sub

Enable Button Code
Private Sub cmdEnable_Click()
On Error Resume Next
Dim DB As DAO.Database
Dim PR As DAO.Property
Set DB = CurrentDb
Set PR = DB.CreateProperty("AllowBypassKey", dbBoolean, True)
DB.Properties.Append PR
DB.Properties("AllowBypassKey") = True
Set PR = DB.CreateProperty("AllowSpecialKeys", dbBoolean, True)
DB.Properties.Append PR
DB.Properties("AllowSpecialKeys") = True
Set PR = DB.CreateProperty("AllowFullMenus", dbBoolean, True)
DB.Properties.Append PR
DB.Properties("AllowFullMenus") = True
Set PR = DB.CreateProperty("AllowDefaultShortcutMenus", dbBoolean, True)
DB.Properties.Append PR
DB.Properties("AllowDefaultShortcutMenus") = True
Set DB = Nothing
MsgBox "Bypass Key Enabled"
End Sub

Text Box Code:
Private Sub Form_Load()
txtBypass.Value = CurrentDb.Properties("AllowBypassKey")
End Sub
 

Attachments

Update- I'm sorry I left out info on the error: Error Message is "Run Time Error 3270" and the "txtBypass.Value = CurrentDb.Properties("AllowBypassKey") is highlighted.
 
I believe it means that there is no property with that name.

you can either trap the error in your error handler or test for the properties existance first and then take the appropriate action.

I use the following to test first
Code:
Function ExistsDBProperty(strPropName As String) As Boolean
    On Error Resume Next

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

    Set db = DBEngine(0)(0)
    Set prp = db.Properties(strPropName)

    If Not prp Is Nothing Then
        ExistsDBProperty = True
    Else
        ExistsDBProperty = False
    End If

    Set prp = Nothing
    Set db = Nothing

End Function

You can also run this in the Immediate window to see which properties are there
Code:
Function ListDBPropsAll() As String
    On Error Resume Next    ' An error occurs whenever this is run

    Dim db As DAO.Database
    Dim i As Long
    Dim strDBP As String
    Set db = DBEngine(0)(0)

    For i = 0 To db.Properties.Count - 1
        If db.Properties(i).Name = "DesignMasterID" Then
            ' Causes an error or long delay so skip it
        Else
            Debug.Print db.Properties(i).Name & " = " & db.Properties(i).Value
            strDBP = strDBP & db.Properties(i).Name & " = " & db.Properties(i).Value & ";"
        End If
    Next i
    
    ListDBPropsAll = strDBP

Exit_ListDBProps:
    Set db = Nothing
    Exit Function
End Function
 
Update- I'm sorry I left out info on the error: Error Message is "Run Time Error 3270" and the "txtBypass.Value = CurrentDb.Properties("AllowBypassKey") is highlighted.

What's happening with the greatest probability is that the property "AllowByPassKey" does not yet exist when the program is first run. You should ignore the error and then click on one of the two buttons which appends the property. That will create the property and the second time around you should not see the 3270 message.

Also, I would like to point out that the code for the buttons unnecessarily recreates the properties. This actually causes errors (which you don't see because of the OnError trap) looks ugly. The properties for the ByPassKey and the Mmenus need to be created only once and then they can be safely referred to. You could use Moke's Property exist function and bypass the appending of the property. Like this:

Code:
Private Sub cmdDisable_Click()
On Error Resume Next
' this should create all referenced properties based on
' the existence of AllowBypassKey
If Not ExistsDBProperty("AllowBypassKey") Then 
     Dim DB As DAO.Database
     Dim PR As DAO.Property
     Set DB = CurrentDb
     Set PR = DB.CreateProperty("AllowBypassKey", dbBoolean, False)
     DB.Properties.Append PR
     DB.Properties("AllowBypassKey") = False
     Set PR = DB.CreateProperty("AllowSpecialKeys", dbBoolean, False)
     DB.Properties.Append PR
     DB.Properties("AllowSpecialKeys") = False
     Set PR = DB.CreateProperty("AllowFullMenus", dbBoolean, False)
     DB.Properties.Append PR
     DB.Properties("AllowFullMenus") = False
     Set PR = DB.CreateProperty("AllowDefaultShortcutMenus", dbBoolean, 
     False)
     DB.Properties.Append PR
     DB.Properties("AllowDefaultShortcutMenus") = False
     Set DB = Nothing
Else
     ChangeProperty "AllowBypassKey", DB_Boolean, False
End If 
MsgBox "Bypass Key Disabled"
End Sub

You would then do the same for the other button with the property set to True in the ELSE portion of the IF statement.

Best,
Jiri
 
Moake & Solo thank you both for your detailed suggestions. I really appreciate the time and effort you spent to help me out. I am going to try out your suggestions when I get back to the office on Monday. I will let you know what happens. Thanks so much!
 
Moake & Solo thank you both for your detailed suggestions. I really appreciate the time and effort you spent to help me out. I am going to try out your suggestions when I get back to the office on Monday. I will let you know what happens. Thanks so much!

You are welcome. Best of luck.

Jiri
 
Hello,

I tried the code suggested and got an error message when compiling:

Compile Error:
Sub or Function not defined.
Else
ChangeProperty "AllowBypassKey", DB_BOOLEAN, False
Any idea how to correct it?

Thank you!
 

Users who are viewing this thread

Back
Top Bottom