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 Westi 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 Error

Status
Not open for further replies.

Fubear

IS-IT--Management
Sep 11, 2002
299
GB
I have the following code on a popup form in an access project:

The form has two check boxes to select enable/disable shift, and a password box for the user to enter a code to verify they didnt find the poopup by accideny ;p

---

If PasswordBox = "abcde" Then
Dim db As Database
If Action.Value = 1 Then
'This Code Disables the Shift Key
Dim prp As Property
Set db = CurrentDb
Set prp = db.CreateProperty("AllowByPassKey", dbBoolean, False)
db.Properties.Append prp
'********************************************************
MsgBox "Database Locked", 0, "Yay!"
Else
'This Code Re-enables the Shift Key
Set db = CurrentDb
db.Properties.Delete "AllowByPassKey"
db.Properties.Refresh
'********************************************************
MsgBox "Database Unlocked", 0, "Yay!"
End If
Else
MsgBox "You Entered The Wrong Password!", 0, "Error!"
End If

---

The error i get is "Object Variable or With Block Variable not set"
breaking on the line:
Set prp = db.CreateProperty("AllowByPassKey", dbBoolean, False)
or:
db.Properties.Delete "AllowByPassKey"
depending on which option was selected

Yes is do have DAO 3.5 set in my referances before anyone asks, and im working with an Access 2000 Project linking to a SQL server backend.

I dont want users sneaking into the server backend, i have locked down everything else but the shift at startup button.
 
poopup - what a typo ;)
---

My debugger shows that the value of db=Nothing. Does this mean that the currentdb command isnt working because of my SQL backend?
 
Found the solution myself, here it is for anyone else who may have the same problem...
---

Private Sub OKButton_Click()

If PasswordBox = "abcde" Then
Dim db As Database
If Action.Value = 1 Then
Application.CurrentProject.Properties.Add "AllowBypassKey", False
MsgBox "Database Locked", 0, "Yay!"
Else
Application.CurrentProject.Properties.Add "AllowBypassKey", True
MsgBox "Database Unlocked", 0, "Yay!"
End If
Else
MsgBox "You Entered The Wrong Password!", 0, "Error!"
End If

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top