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

How to show different data sets dependant on the users password

Status
Not open for further replies.

malcprice

Technical User
Feb 27, 2002
20
GB

I wish to only show a records which apply to them. My company has a number of subsidiaries but we only want them to view/edit their own records in the predefined forms.

Also the reports which have already been made they can also all view.

How can you achieve this? I was thinking of Passwording the database and on entering it a query/filter would then segment the data dependant of this.

Is this possible

Many thanks

Malc

 
Well, for a start neither YOU or the Database has access to the User's Password once they have entered the database. ( Single Direction Encryption - and all that - don't ya know. )

So in reality you mean USERNAME rather than password.

Will each user have a user name, or will everyone from a site log on as a single username ?

If the latter then you can store the user name in a field in the table and filter the table against the value in CurrentUser()

If the Former, then you'll need to allocate users to Groups, then check which Group(s) a User is a member of ( I can drop you the code for that if you need it ) and then filter the records according to Group membership.


Other thoughts:-
If they all want personal Usernames - How many users per site.

Will some ( super users ) want access to ALL records ?



'ope-that-'elps.

G LS
accessaceNOJUNK@valleyalley.co.uk
Remove the NOJUNK to use.

Please remember to give helpful posts the stars they deserve!
This makes the post more visible to others in need! :-D

 
Once they entered username and Password in login form.Assign both to two global variables.

sgUserName=Me![txtUsername]
sgPassword=Me![Password]

Then In Form Load or Form Open event of in any your predefined forms.Use SgUserName or sgPassword as Filter,whichever is unique.
Me.Filter = sgUserName
Me.FilterOn = True
Hope this Help
Please remember to give helpful posts the stars they deserve!
This makes the post more visible to others in need!
 
OK, thanks,

There will be about 10 groups with 2 users to each group. So about 20 USERNAMES

As for Superusers there would be 1 group of 3 users which would need access to all records.

With this could I allow a user to view all reports?

Any code would be appreciated but even more help would be an explanation of what the code does would help increse my knowledge.

Many thanks

Malc
 
Install the following code in a global module ( I call mine mdlSecurity )

Code:
Public Function InGroup(strGroupName As String) As Boolean
'#######################################################'
' The public face of this Module's code collection      '
'#######################################################'
' This function will return TRUE IF the current user is a member of a _
security user Group with a name matching the string provided in the argument.
On Error GoTo Err_InGroup
' HOWEVER, First it needs to check that the ADOX reference is included in the
' Reference library list because not everyone has this library linked
' Yet it is needed for the Catalog object.
    
    ' CheckSetRef is located in the global module mdlReferences
    ' It checks for the Reference by name in the first parameter
    ' and if it does not exist, looks for it at the location in the second parameter.
    ' Only if it fails to verify or establish the link does it return false.
If CheckSetRef("ADOX", "C:\PROGRAM FILES\COMMON FILES\SYSTEM\ADO\MSADOX.DLL") Then
    ' All is well - Take no action
Else
    InGroup = False
    MsgBox "There is a problem with the set up of your local copy of MS Access." & vbLf _
            & "You need the ADOX Library Reference Set." & vbLf _
            & "I attempted to set this for you, but the file I expected to find at " & vbLf _
            & "C:\PROGRAM FILES\COMMON FILES\SYSTEM\ADO\MSADOX.DLL" & vbLf _
            & "was not there." & vbLf _
            & "Please get an Access Administrator to add this reference.", _
            , "I can't find the file I need."
    Exit Function
End If

InGroup = ProtectedInGroup(strGroupName)
Exit Function

Err_InGroup:
If Err.Number = 3265 Then
    MsgBox "The Group Name provided in the InGroup() function call '" _
         & strGroupName & "'" & vbLf & " does not match a group name in the current " _
         & "system.mdw file.", , "Code Error"
Else
    MsgBox Err.Description, , Err.Number
End If

End Function

Private Function ProtectedInGroup(strGroupName As String) As Boolean
'###################################################################'
' The ADOX library is not linked by default.                        '
' However it is vital for this piece of code to operate             '
' Therefore, then InGroup Function just checks to see               '
' if the Library is present & links it if not.                      '
' ProtectedInGroup can then go and use the library.                 '
' If the procs were not split in this way the line                  '
' Dim cat As New ADOX.Catalog would cause a Run Time Compile Error  '
' before the linking code could do it's work.                       '
'###################################################################'

Dim lngPerm As Long

Dim conn As Connection
Set conn = New ADODB.Connection
Set conn = CurrentProject.Connection
Dim cat As New ADOX.Catalog
Set cat.ActiveConnection = conn
    
ProtectedInGroup = False
Dim usrUser As User
For Each usrUser In cat.Groups(strGroupName).Users
    If usrUser = CurrentUser Then
        ProtectedInGroup = True
        Exit Function
    End If
Next
End Function


Public Function CheckSetRef(RefName As String, RefPath As String) As Boolean
'###################################################################'
' Checks to see if a Refernce exist that matches RefName            '
' AND check that the link is not broken.                            '
' If the check fails then it sets up a link using RefPath           '
'                                                                   '
' Returns True if check turned out Okay or if  link was successful  '
'###################################################################'
    
    Dim ref As Reference
    
    CheckSetRef = False
    For Each ref In Application.References
        If ref.Name = RefName _
         And ref.IsBroken = False _
         Then CheckSetRef = True
    Next
    
    If CheckSetRef Then
        ' Link to Reference library exists so make no change
    Else
        CheckSetRef = ReferenceFromFile(RefPath)
    End If

End Function

Private Function ReferenceFromFile(strFileName As String) As Boolean
'###################################################################'
' Used by Function above to do the establishing of the Reference    '
'###################################################################'

    Dim ref As Reference

    On Error GoTo Error_ReferenceFromFile
    Set ref = References.AddFromFile(strFileName)
    ReferenceFromFile = True

Exit_ReferenceFromFile:
    Exit Function

Error_ReferenceFromFile:
    MsgBox Err & ": " & Err.Description, , Err.Number
    ReferenceFromFile = False
    Resume Exit_ReferenceFromFile
End Function

G LS
accessaceNOJUNK@valleyalley.co.uk
Remove the NOJUNK to use.

Please remember to give helpful posts the stars they deserve!
This makes the post more visible to others in need! :-D

 
Then set up the standard Access Security model and have separate groups for each of the site locations.

Then on Login you'll need to cycle through the groups collection to find out which group the user is a member of.
Set that group name to a global variable.

Have a field in the data table that contains the 'groupname' of the user who created the record ( this can easily be done by adding a hidden control on the form and using code in the On_Current event to check it the field is null and if so setting the value to the global variable.

Therewafter, it is simple a matter of filtering every form on the value of the global variable in the user's group field.




'ope-that-'elps.


G LS
accessaceNOJUNK@valleyalley.co.uk
Remove the NOJUNK to use.

Please remember to give helpful posts the stars they deserve!
This makes the post more visible to others in need! :-D

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top