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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable shift key code giving error. 1

Status
Not open for further replies.

mpm32

Technical User
Feb 19, 2004
130
0
0
US
I made a database a while ago that I haven't used in a while. Since then, my computer crashed and I had to get re-imaged. I think that the error is related to the references I have chosen no longer being selected on my re-imaged pc.

The problem is, I am not sure which ones I need to make the code work.

The error I get is "Run time error 3265" Item not found in this collection.

The code I am using is;

to disable
Code:
Private Sub DisableShiftKey_Click()
'This code disables shift key'

    Dim db As DAO.Database
    Dim prp As Property
    
    Set db = CurrentDb
    
    Set prp = db.CreateProperty("allowbypasskey", dbBoolean, False)
    
    db.Properties.Append prp
End Sub

to enable;

Code:
Private Sub EnableShiftKey_Click()
'This code re-enables shift key'

    Dim db As DAO.Database
    
    Set db = CurrentDb

    db.Properties.Delete "allowbypasskey"
    
    db.Properties.Refresh

End Sub

When I debug, I get the line db.Properties.Delete "allowbypasskey" highlighted.

The references I have checked are;

Visual Basic for Applications
Microsoft Access 9.0 Object Library
Microsoft DAO 3.6 Object Library
OLE Automation
Microsoft ActiveX Data Objects 2.1 Library
Microsoft Access Visual Basic for Applications Extensibility 5.3


Can anyone point me to the reference that I should choose to make the code work?

Thanks in advance.
 
the data base "Properties" is a collection.
You refer to objects in a collection by their name or index.

That error is telling you that there is not a property named
"allowByPassKey". This is not a directly a reference issue.

It sounds like this code never executes:
Set prp = db.CreateProperty("allowbypasskey", dbBoolean, False)

and thus the property is never created.

But that is any easy test. Before running your delete code run this:
Public Sub printProperties()
Dim prp As Property
For Each prp In CurrentDb.Properties
Debug.Print prp.Name
Next prp
End Sub

and see if your property exists. I can tell you right now it does not.
 
AllowBypassKey is simply true or false btw it is case sensitive

Why not just set the properties to true of false?

There is a nice little bit of code available here that does just that


HTH << MaZeWorX >> "I have not failed I have only found ten thousand ways that don't work
 
Well thanks for you suggestions and help. It turns out it was user error. i.e. me.

The property was never created because I never initiated the code to disable the shift key. So of course when I was trying to enable it I was getting the error.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top