V
vandy
Hi All,
I have been doing some search on this topic and require some coding help.
I want to create a login form which checks for username, pwd and
securitylevel and accordingly give access to certain queries , forms and
reports. I do not want to use the Access user level security wizard and want
to create a separate security module.
I have come across this code posted by Klatuu which is probably the solution
i am looking for.
Public Function SetSecurityProp(UserInitials As String, SecurityLevel As
Integer) As Boolean
Dim prp As Property
Const conPropNotFound As Integer = 3270
On Error GoTo ErrorSetSecurityProp
' Explicitly refer to Properties collection.
CurrentDb.Properties("User") = UserInitials
CurrentDb.Properties.Refresh
CurrentDb.Properties("SecurityLevel") = SecurityLevel
CurrentDb.Properties.Refresh
SetSecurityProp = True
ExitSetSecurityProp:
Exit Function
ErrorSetSecurityProp:
If Err = conPropNotFound Then
' Create property, denote type, and set initial value.
Set prp = CurrentDb.CreateProperty("User", dbText, UserInitials)
' Append Property object to Properties collection.
CurrentDb.Properties.Append prp
CurrentDb.Properties.Refresh
Set prp = CurrentDb.CreateProperty("SecurityLevel", dbInteger,
SecurityLevel)
' Append Property object to Properties collection.
CurrentDb.Properties.Append prp
CurrentDb.Properties.Refresh
SetSecurityProp = True
Resume ExitSetSecurityProp
Else
MsgBox Err & ": " & vbCrLf & Err.DESCRIPTION
SetSecurityProp = False
Resume ExitSetSecurityProp
End If
End Function
Function ChangeProperty(strPropName As String, varPropType As Variant,
varPropValue As Variant) As Integer
Dim dbs As Object, prp As Variant
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 ' Property not found.
Set prp = dbs.CreateProperty(strPropName, _
varPropType, varPropValue)
dbs.Properties.Append prp
Resume Next
Else
' Unknown error.
ChangeProperty = False
Resume Change_Bye
End If
End Function
I want to know how to implement this. What is the table i should create and
should i use this code as a module and how and were to call it.
How to implement case SecurityLevel =1
open form A
query A
case SecurityLevel =2
open form b
etc...
Would really appreciate if someone can help me out with this. I am not too
much of a progammer but i am willing to learn.
I have been doing some search on this topic and require some coding help.
I want to create a login form which checks for username, pwd and
securitylevel and accordingly give access to certain queries , forms and
reports. I do not want to use the Access user level security wizard and want
to create a separate security module.
I have come across this code posted by Klatuu which is probably the solution
i am looking for.
Public Function SetSecurityProp(UserInitials As String, SecurityLevel As
Integer) As Boolean
Dim prp As Property
Const conPropNotFound As Integer = 3270
On Error GoTo ErrorSetSecurityProp
' Explicitly refer to Properties collection.
CurrentDb.Properties("User") = UserInitials
CurrentDb.Properties.Refresh
CurrentDb.Properties("SecurityLevel") = SecurityLevel
CurrentDb.Properties.Refresh
SetSecurityProp = True
ExitSetSecurityProp:
Exit Function
ErrorSetSecurityProp:
If Err = conPropNotFound Then
' Create property, denote type, and set initial value.
Set prp = CurrentDb.CreateProperty("User", dbText, UserInitials)
' Append Property object to Properties collection.
CurrentDb.Properties.Append prp
CurrentDb.Properties.Refresh
Set prp = CurrentDb.CreateProperty("SecurityLevel", dbInteger,
SecurityLevel)
' Append Property object to Properties collection.
CurrentDb.Properties.Append prp
CurrentDb.Properties.Refresh
SetSecurityProp = True
Resume ExitSetSecurityProp
Else
MsgBox Err & ": " & vbCrLf & Err.DESCRIPTION
SetSecurityProp = False
Resume ExitSetSecurityProp
End If
End Function
Function ChangeProperty(strPropName As String, varPropType As Variant,
varPropValue As Variant) As Integer
Dim dbs As Object, prp As Variant
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 ' Property not found.
Set prp = dbs.CreateProperty(strPropName, _
varPropType, varPropValue)
dbs.Properties.Append prp
Resume Next
Else
' Unknown error.
ChangeProperty = False
Resume Change_Bye
End If
End Function
I want to know how to implement this. What is the table i should create and
should i use this code as a module and how and were to call it.
How to implement case SecurityLevel =1
open form A
query A
case SecurityLevel =2
open form b
etc...
Would really appreciate if someone can help me out with this. I am not too
much of a progammer but i am willing to learn.