We help IT Professionals succeed at work.

AllowBreakIntoCode not working

Milewskp
Milewskp asked
on
600 Views
Last Modified: 2012-05-05
I set the AllowBreakIntoCode property to False, close the database, open it, and close it again.
Then I open it and run a routine with the following statement in it:
a = 3/ 0.
As expected, an error dialogue box appears. What I don't expect is that the Debug button is enabled, and allows me to see the code!

What am I doing wrong?
Comment
Watch Question

Author

Commented:
Note: I'm using this name for the property:  
   AllowBreakIntoCode
(there are no spaces before or after)
CERTIFIED EXPERT
Top Expert 2016

Commented:
how did you  do it?
did you add it to the Properties collection of the Database object?

you can add it by using the CreateProperty method
and append it to the Properties collection of the Database object.

Author

Commented:
Hi cap,
here's the code (I call Disallowbreak via a RunCode macro command):

Function DisallowBreak()
      Call iiChangeDbProp("AllowBreakIntoCode", False, dbBoolean)  
End Function

Public Sub iiChangeDbProp(PropName As String, Optional NewValue As Variant, _
Optional PropDataType As Variant)
Const ProcID = "c000.049"
    'This macro creates, deletes or changes the value of property PropName of the current database.
    'To create a new property, NewValue and PropDataType must be provided.
    'To delete an existing property, then NewValue should be missing or Isblank(NewValue) should be true,
    'To change the value of existing property PropName, provide NewValue.
   
    'Notes:
    ' - You can create/ change you own, custom properties.
    ' - PropDataType is the data type of the property, and is required only when creating new properties;
    '   use one of the following values:
    '   - dbBigInt    Big Integer
    '   - dbBinary    Binary
    '   - dbBoolean   Boolean
    '   - dbByte      Byte
    '   - dbChar      Char
    '   - dbCurrency  Currency
    '   - dbDate      Date / Time
    '   - dbDecimal   Decimal
    '   - dbDouble    Double
    '   - dbFloat     Float
    '   - dbGUID      Guid (Global Unique Identifier)
    '   - dbInteger   Integer
    '   - dbLong      Long
    '   - dbLongBinary Long Binary (OLE Object)
    '   - dbMemo      Memo
    '   - dbNumeric   Numeric
    '   - dbSingle    Single
    '   - dbText      Text
    '   - dbTime      Time
    '   - dbTimeStamp Time Stamp
    '   - dbVarBinary VarBinary
    '   For more info, click F1 over the CreateProperty method below,
    '   and then click on the 'Type' hyperlink.
    '
    ' - If PropDataType is missing when trying to create a new property, then error.
    ' - If NewValue is not compatible with the existing property's DataType, then error.
    ' - If NewValue is not compatible with the PropTypeType provided for the new property, then error.

    Dim prop As DAO.Property
   
    On Error GoTo UnexpectedError
   
    On Error Resume Next
        If IsMissing(NewValue) Or IsBlank(NewValue) Then 'Attempt to delete property
            CurrentDb.Properties.Delete PropName
            If Err = conPropertyNotFoundError Or Err = conItemNotInCollectionError Then
                'Attempted to delete non-existant property (no problem).
                Err.Clear
            ElseIf Err <> 0 Then
                Call iiUnexpectedError(ProcID)
            End If
           
        Else  'NewValue provided, so attempt to change property value
            MsgBox "Current Value of " & PropName & ": " & CurrentDb.Properties(PropName).Value
            CurrentDb.Properties(PropName) = NewValue
            MsgBox "New Value of " & PropName & ": " & CurrentDb.Properties(PropName).Value
            If Err = conNoDbAdminRights Then
               If ThisIsDevDB Then
                     Err.Description = "You do not have rights to change database properties."
                     Err.Raise 1000
                     Call iiUnexpectedError(ProcID)
                  Else
                     Err.Clear
                     GoTo Quitsub
                  End If
               End If
                 
             If Err = conPropertyNotFoundError Or Err = conItemNotInCollectionError Then
                 Err.Clear
                'Property doesn't exist, so attempt to create it
                 If IsMissing(PropDataType) Then
                     Err.Description = "PropDataType argument must be provided when creating new properties."
                     Err.Raise 1000
                     Call iiUnexpectedError(ProcID)
                 End If
                 Set prop = CurrentDb.CreateProperty(PropName, PropDataType, NewValue)
                 If Err Then Call iiUnexpectedError(ProcID)
                 Err.Clear
                 CurrentDb.Properties.Append prop
                 If Err Then Call iiUnexpectedError(ProcID)
             ElseIf Err <> 0 Then
                Call iiUnexpectedError(ProcID)
            End If
        End If

    On Error GoTo UnexpectedError
   
GoTo Quitsub
'_______________________________________________________________________________________
UnexpectedError:
    Call iiUnexpectedError(ProcID)
    Resume
'_______________________________________________________________________________________
Quitsub:
    On Error Resume Next
        Set prop = Nothing
    On Error GoTo UnexpectedError
   
End Sub




CERTIFIED EXPERT
Top Expert 2016
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Hi cap,
You're a genius!

I tried it and it worked! In order to allow breaking into code, both properties must be set to true; in order to prevent breaking into code, both properties must be false.

I never would have guessed in a million years. God bless EE and god bless you!
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.