Disable ByPass Key

D

Duane

I am having some difficulty with this code and am wondering if someone can
give me some assistance. I am experiencing this problem with all newly
created databases.

I have a label on my switchboard with the following code:

Private Sub bDisableBypassKey_DblClick(Cancel As Integer)
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?"
strInput = InputBox(Prompt:=strMsg, Title:="Disable Bypass Key Password")
If strInput = "PASSWORD" Then 'just kidding, it isn't the real password
SetProperties "AllowBypassKey", dbBoolean, True
Beep
MsgBox "The Bypass Key has been enabled.", _
vbInformation, "Set Startup Properties"
Else
Beep
SetProperties "AllowBypassKey", dbBoolean, False
MsgBox "Incorrect ''AllowBypassKey'' Password!" & vbCrLf & vbLf & _
"The Bypass Key was disabled.", _
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
---------------

I have a module with the rest of the code:

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

I am using XP Office. I have my Library references set the same as with the
databases that this code is working correctly in, including the DAO
reference. When I double click the label and enter the password I receive
the following error; Run Time Error 3270. Property not found. I set a
breakpoint and stepped through the code and have found the code breaking on
the db.Properties(strPropName) = varPropValue. When I hover over the
breakpoint, I see where it tells me db.Properties(strPropName) = <Property
Not Found>. If I go to the first line in the function where it says Public
Function SetProperties(strPropName As String, - and hover over the
variable it tells me strPropName = "AllowByPassKey"

I sure could use some help. But for now, it's bedtime. Thanks in advance.
 
A

Armen Stein

I receive
the following error; Run Time Error 3270. Property not found. I set a
breakpoint and stepped through the code and have found the code breaking on
the db.Properties(strPropName) = varPropValue. When I hover over the
breakpoint, I see where it tells me db.Properties(strPropName) = <Property
Not Found>. If I go to the first line in the function where it says Public
Function SetProperties(strPropName As String, - and hover over the
variable it tells me strPropName = "AllowByPassKey"

The AllowBypassKey property doesn't exist by default in an Access
database - you need to create it first.

For help, see:

http://office.microsoft.com/en-us/access/HA012327171033.aspx

and

http://www.access-programmers.co.uk/forums/showthread.php?t=131484

Armen Stein
Microsoft Access MVP
www.JStreetTech.com
 
D

Duane

If I am not mistaken, the error handler should be creating the property when
the code breaks and then resuming. I am new at this and I am not sure.

It just seems odd that I use this code in about 10 different databases and
it works just fine, but I created a new database, imported my modules and
viola, I am now getting this error.
 
A

Armen Stein

If I am not mistaken, the error handler should be creating the property when
the code breaks and then resuming. I am new at this and I am not sure.

Sorry, I missed that. You're right, it should be creating the
property when it needs to.

Try putting a breakpoint down in the error handler to see if the error
handler is running and the expected error number is being generated.
If you find that your error code is not running at all, your compiled
VBA code may be corrupted. In that case, try a /decompile (command
line startup option), and if that fails, copy everything into a new
database container. If you use a new mdb container, check your
References to make sure they remain intact.
It just seems odd that I use this code in about 10 different databases and
it works just fine, but I created a new database, imported my modules and
viola, I am now getting this error.

That leads me to think that a) something is corrupted in this
database, b) the other databases were all copied from one that already
had this property so this code never ran, or c) this code was
inadvertently changed in this particular database.

Armen Stein
Microsoft Access MVP
www.JStreetTech.com
 
D

Duane

Thank you for taking the time to respond.

I inserted a breakpoint and the code breaks right in the beginning and never
runs the error code.
db.Properties(strPropName) = varPropValue
When the code breaks, I go into debug and the above line of code is yellow.
It states that db.Properties(strPropName) = <Property Not Found>.
The error code is never run. Here is the actual code including the error
code.

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

I tried the /decompile and nothing. I created a blank database. I imported
the form from a database where I know the code is working correctly. I
imported my module containing the above code. I checked and made sure my
DAO reference is correct. but I am still getting the same error..

I uninstalled Office and re-installed it. Still the same thing. I have
even created a blank database, used two other types of code I found on the
internet to achieve what I am trying to do, but every time the code breaks
on the set property part of the code.

Any other ideas would be greatly appreciated.
 
A

Armen Stein

I inserted a breakpoint and the code breaks right in the beginning and never
runs the error code.
db.Properties(strPropName) = varPropValue
When the code breaks, I go into debug and the above line of code is yellow.
It states that db.Properties(strPropName) = <Property Not Found>.
The error code is never run.

Hmm. I'm running low on ideas.

This would be an unusual one, but I wonder...
In the VBA code window, select Tools..Options. Click the General tab.
Make sure Error Trapping is set to Break on Unhandled Errors.

Armen Stein
Microsoft Access MVP
www.JStreetTech.com
 
D

Duane

That was the ticket. The Error Trapping was set to Break On All Errors.
And just to let you know, I went to the databases where I know the code is
working correctly and the Error Trapping is set to Break on Unhandled
Errors. I wonder how it got changed, but more important, I wonder how I can
get that to be the default on all new databases?

Thank you very much.
 
A

Armen Stein

That was the ticket. The Error Trapping was set to Break On All Errors.
And just to let you know, I went to the databases where I know the code is
working correctly and the Error Trapping is set to Break on Unhandled
Errors. I wonder how it got changed, but more important, I wonder how I can
get that to be the default on all new databases?

Wow, I'm glad that was it. It didn't occur to me at first because
that setting is rarely changed by anyone. Break on Unhandled Errors
is the default.

After a bit of testing in Access 2003 to make sure, I found that the
setting appears to be global for on your PC. It isn't set for each
database. So you should find that when you change it, it should be
consistent across all databases you open on that PC.

Armen Stein
Microsoft Access MVP
www.JStreetTech.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Disable/Enable the Shift Bypass Key 3
Shift Key 9
AllowByPassKey 6
Access Shift By Pass 3
AllowBypass Key 6
Run-time error 3
Error 429 in Runtime 0
help with coding - for creating secure login forms 1

Top