Problem with shif key Disable (1 Viewer)

morteza76

New member
Local time
Tomorrow, 03:20
Joined
Jul 18, 2022
Messages
8
hi i have a problem with disabling shift key
this is my module code
Code:
Option Compare Database

Sub DisableShiftKey()
   Dim db As DAO.Database
   Dim prp As DAO.Property
  
   Set db = CurrentDb
   On Error Resume Next
   db.Properties.Delete "AllowBypassKey"
   On Error GoTo 0
   Set prp = db.CreateProperty("AllowBypassKey", dbBoolean, False, True)
   db.Properties.Append prp
  
   db.Properties.Refresh
  
   Set prp = Nothing
   Set db = Nothing
End Sub
Sub EnableShiftKey()
   Dim db As DAO.Database
   Dim prp As DAO.Property
  
   Set db = CurrentDb
   On Error Resume Next
   db.Properties.Delete "AllowBypassKey"
   On Error GoTo 0
   Set prp = db.CreateProperty("AllowBypassKey", dbBoolean, True, True)
   db.Properties.Append prp
  
   db.Properties.Refresh
  
   Set prp = Nothing
   Set db = Nothing
End Sub
and when i save this and put two buttom for enable and disabling when i run it comes with an error and the problem is with my code for opening my main menu after login page with runtime error 2501
with this code
DoCmd.OpenForm "frmMain"
 

CJ_London

Super Moderator
Staff member
Local time
Today, 22:50
Joined
Feb 19, 2013
Messages
16,553
What is the description of error 2501? And where are the buttons that run the code?
 

MarkK

bit cruncher
Local time
Today, 15:50
Joined
Mar 17, 2004
Messages
8,178
Not to your question, but your code could be expressed as...
Code:
Private Const PN As String = "AllowBypassKey"

Sub DisableShiftKey()
    SetBypassKeyState False
End Sub

Sub EnableShiftKey()
    SetBypassKeyState True
End Sub

Private Sub SetBypassKeyState(State As Boolean)
    With CurrentDb
        On Error Resume Next
            .Properties.Delete PN
        On Error GoTo 0
        .Properties.Append .CreateProperty(PN, dbBoolean, State, True)
        .Properties.Refresh
    End With
End Sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:50
Joined
May 7, 2009
Messages
19,169
because you disabled error handling, try:
Code:
Sub DisableShiftKey()
Call byPassKey(False)
End Sub

Sub EnableShiftKey()
Call byPassKey(True)
End Sub

Private Sub byPassKey(ByVal bolAllow As Boolean)
    Const PropertyName As String = "AllowBypassKey"
    Const PropertyType As Integer = 1
    Dim db As DAO.Database
    Dim prp As DAO.Property
    
On Error GoTo Err_Handler:
    Set db = CurrentDb
    db.Properties(PropertyName) = bolAllow
    db.Properties.Refresh
Exit_Sub:
    Set prp = Nothing
    Set db = Nothing
    Exit Sub
Err_Handler:
    If Err.Number = 3270 Then
        Set prp = db.CreateProperty(PropertyName, PropertyType, bolAllow)
        db.Properties.Append prp
        Resume Next
    Else
        Resume Exit_Sub
    End If
    
End Sub
 

Users who are viewing this thread

Top Bottom