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!

Check for ByPassKey True/False 1

Status
Not open for further replies.

Binnit

Technical User
Apr 28, 2004
627
0
0
US
I wish to check the status of the ByPassKey property in a form module and have the following code (which doesn't work)

Code:
If dbs.Properties("allowbypasskey") = True Then
Me.cmdLockDB.Enabled = True
Me.cmdUnlockDB.Enabled = False

Else
Me.cmdUnlockDB.Enabled = True
Me.cmdLockDB.Enabled = False
End If

The syntax is wrong but I'm not sure how to test for the property value.

Any help appreciated.
Thanks

If IT ain’t working Binnit and Reboot
 
Binnit

I normally refer to a field on the form...

If Me.allowbypasskey Then
....
etc

I am assuming "allowbypasskey" is a field name on your form. Since it is a true/false field, you don't really need to use the "="; rather, paraphrase "If this is true...
 
Willir
Yeah thats ok for field but doesn't seem to work for a db property setting.

If IT ain’t working Binnit and Reboot
 
Untested.. but try..
Code:
Function CheckBypass() As Integer
    Dim dbs As Object, prp As Variant
    Const conPropNotFoundError = 3270

    Set dbs = CurrentDb
    On Error GoTo Check_Err

If dbs.Properties("AllowBypassKey") = true then
 checkbypass = true
Else
 CheckBypass = False
end if

Check_Bye:
    Exit Function

Check_Err:
    If Err = conPropNotFoundError Then    ' Property not found.
        Set prp = dbs.CreateProperty("AllowBypassKey", _
            DB_Boolean, True)
        dbs.Properties.Append prp
        Resume Next
    Else
        ' Unknown error.
        Resume Check_Bye
    End If
End Function

------------------------
Hit any User to continue
 
SIJP
This is looking good, I have tried it out and need to straighten a few other bits and bobs, I will post back when completed.

Thanks
Binnit


If IT ain’t working Binnit and Reboot
 
SIJP
I have now tidied up and all is working well thanks to your help.

Have a star on me for a good posting.


If IT ain’t working Binnit and Reboot
 
Good stuff... wanna post your final code so others can see? :D

------------------------
Hit any User to continue
 
The idea behind this is to identify the current status of the Shift ByPass property as part of basic Admin form

Heregoes
On my form there is:
1 Textbox with Password Input Mask
2 Command buttons to Lock and Unlock

Code:
[b]The following is conatined within the form module[/b]
'===================================================== 

Private Sub cmdLockDB_Click()
 ChangeProperty "AllowBypassKey", dbBoolean, False
 MsgBox "Database Now Locked", vbOKOnly

End Sub
'===================================================== 

Private Function CheckPassword()

If Me.txtPassword = "stacemppp" Then
MsgBox "Password Accepted", _
vbOKOnly, "Welcome Database Administrator"
    
    If CheckBypass = False Then  'Bypass not allowed as previously locked
 
Me.cmdLockDB.Enabled = False
Me.cmdUnlockDB.Enabled = True
Me.cmdUnlockDB.SetFocus
    Else
Me.cmdUnlockDB.Enabled = False
Me.cmdLockDB.Enabled = True
Me.cmdLockDB.SetFocus
    End If

Me.txtPassword.Enabled = False
Exit Function
Else
MsgBox "Incorrect Password Entered, Application will now shutdown", vbOKOnly, "Password Unaccepted"
DoCmd.Quit
Me.txtPassword = Null
End If


End Function
'===================================================== 

Private Sub cmdUnlockDB_Click()
  ChangeProperty "AllowBypassKey", dbBoolean, True
MsgBox "Database Unlocked for modification" & vbCr & "Database will now quit and you will need to re-open using the Shift F1 keys", _
vbOKOnly, "Database Unlocked!"
DoCmd.Quit
End Sub
'===================================================== 

Private Sub Form_Open(Cancel As Integer)
Me.cmdUnlockDB.Enabled = False
Me.cmdLockDB.Enabled = False

End Sub
'===================================================== 

Private Sub txtPassword_AfterUpdate()
CheckPassword
End Sub
'===================================================== 

[b]The following is contained within a Database module[/b]
'===================================================== 

Function ChangeProperty(strPropName As String, varPropType As Variant, varPropValue As Variant) As Integer

    Dim dbs As Database, prp As Property
    Const conPropNotFoundError = 3270
    Set dbs = CurrentDb
    
    On Error GoTo Change_Err
    
    dbs.Properties(strPropName) = varPropValue
    ChangeProperty = True
Change_Bye:
    Exit Function
Change_Err:
    If Err = conPropNotFoundError Then
        Set prp = dbs.CreateProperty(strPropName, varPropType, varPropValue)
        dbs.Properties.Append prp
        Resume Next
    Else
        ChangeProperty = False
        Resume Change_Bye
    End If
    
End Function
Function CheckBypass() As Integer
    Dim dbs As Object, prp As Variant
    Const conPropNotFoundError = 3270

    Set dbs = CurrentDb
    On Error GoTo Check_Err

If dbs.Properties("AllowBypassKey") = True Then
 CheckBypass = True
Else
 CheckBypass = False
End If

Check_Bye:
    Exit Function

Check_Err:
    If Err = conPropNotFoundError Then    ' Property not found.
        Set prp = dbs.CreateProperty("AllowBypassKey", _
            DB_BOOLEAN, True)
        dbs.Properties.Append prp
        Resume Next
    Else
        ' Unknown error.
        Resume Check_Bye
    End If
End Function

Hope this helps someone else


If IT ain’t working Binnit and Reboot
 
Nice one.. star for the complete code.. im sure it will be useful for other!

------------------------
Hit any User to continue
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top