Solved

code problem

Posted on 2002-04-27
10
156 Views
Last Modified: 2010-08-05
the code below doesn't seem to work properly!  
if the user has "Admin" selected in the table then it works but
if "Admin" is not selected then none of the buttons are visible
that should be!

i am trying to create different types of access to a form. Ie
admin - has FULL access
DeleteAccess - where user can delete, add, update a record
WriteAccess - where a user can only add, update a record

Function AllowAccess()

   If IsAdmin = False Then
      cmdDelete.Visible = False
      cmdUpdate.Visible = False
      cmdNew.Visible = False
      Call LockRecords
      lblNotice.Caption = ""
      lblNotice.Visible = False

   Else
       
      If IsAdmin = True Then
        cmdDelete.Visible = True
        cmdUpdate.Visible = True
        cmdNew.Visible = True
        Call UnlockRecords
        lblNotice.Caption = "Administrator Access, Read, Write, Delete!"
        lblNotice.Visible = True
      Else

         If WriteAccess = False Then
            cmdDelete.Visible = False
            cmdUpdate.Visible = False
            cmdNew.Visible = False
            Call LockRecords
            lblNotice.Caption = "Read Access Only!"
            lblNotice.Visible = True

         Else
               
            If WriteAccess = True Then
               cmdDelete.Visible = False
               cmdUpdate.Visible = True
               cmdNew.Visible = True
               Call UnlockRecords
               lblNotice.Caption = "Read, Write, Update access!"
               lblNotice.Visible = True

            Else
                   
               If DeleteAccess = False Then
                  cmdDelete.Visible = False
                  cmdUpdate.Visible = True
                  cmdNew.Visible = True
                  Call UnlockRecords
                  lblNotice.Caption = "Read, Write, Update access!"
                  lblNotice.Visible = True

               Else
                       
                  If DeleteAccess = True Then
                     cmdDelete.Visible = True
                     cmdUpdate.Visible = True
                     cmdNew.Visible = True
                     Call UnlockRecords
                     lblNotice.Caption = "Read, Write, Update, Delete access!"
                     lblNotice.Visible = True
                  End If
               End If
            End If
         End If
      End If
   End If

End Function

the fields in the table are as follows, i have already connected to the table with the following variables

IsAdmin
WriteAccess
DeleteAccess

table fields

username
password
admin - checkbox - true/false
DeleteAccess - checkbox - true/false
WriteAccess - checkbox - true/false

cheers
0
Comment
Question by:marksmall
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 6973730
Are the buttons mutually exclusive?

Try this

Function AllowAccess()

     If IsAdmin = True Then
       cmdDelete.Visible = True
       cmdUpdate.Visible = True
       cmdNew.Visible = True
       Call UnlockRecords
       lblNotice.Caption = "Administrator Access, Read, Write, Delete!"
       lblNotice.Visible = True
 
     Else If WriteAccess = True Then
          cmdDelete.Visible = False
          cmdUpdate.Visible = True
          cmdNew.Visible = True
          Call UnlockRecords
          lblNotice.Caption = "Read, Write, Update access!"
          lblNotice.Visible = True

     Else If DeleteAccess = True Then
           cmdDelete.Visible = True
           cmdUpdate.Visible = True
           cmdNew.Visible = True
           Call UnlockRecords
           lblNotice.Caption = "Read, Write, Update, Delete access!"
           lblNotice.Visible = True
     End If

The way you have it If they don't have admin access then the first all are turned off but the others aren't checked

Remember

If  IsAdmin = False  then
   This gets done
Else  
   This is done only if isAdmin is true
endif

good luck
mlmcc

0
 

Author Comment

by:marksmall
ID: 6973774
what do you mean by mutually exclusive?

what about the, if IsAdmin  = false statements etc

do i have to include them with the code you specified?
0
 
LVL 3

Expert Comment

by:Gunsen
ID: 6974016
Your if-nesting logic is somewhat screw'ed up.
Here is a sample logic :

If IsAdmin Then
  ' Admin
Else
  If WriteAccess Then
    If DeleteAccess Then
      ' Assume Delete access requires Write...
    EndIf
  Else
    ' Read access by default !
  EndIf
EndIf
0
 
LVL 3

Expert Comment

by:Gunsen
ID: 6974018
If IsAdmin Then
 ' Admin
Else
 If WriteAccess Then
   If DeleteAccess Then
     ' Assume Delete access requires Write...
   Else
     ' Write access
   EndIf
 Else
   ' Read access by default !
 EndIf
EndIf
0
 
LVL 3

Expert Comment

by:Gunsen
ID: 6974026
The (first) actual error in your code is

  If IsAdmin = False Then
    ' Well here we are if admin is false, ok
  Else
     If IsAdmin = True Then
       ' Here we will allways be since (admin wasnt false), and none of the other if's are executed...
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 100

Expert Comment

by:mlmcc
ID: 6974192
Mutually exclusive means a record can have only one check.  For example if a person has Admin he doesn't have DeleteAccess or WriteAccess.

You don't have to include the tests for false because these turn off permissions that may be needed by a person with other permissiions.  For example

  If a person has admin then a test for WriteAccess=False will turn off the WriteAccess permissions.

What you should do is default permissions off and then test for granted permissions and turn on the permissions granted.

The order I tested in tests first for the greatest permissions then the next etc.  In this way if the permissiions aren't mutually exclusive the person will be granted the highest level he has.

If you need a better explanation just ask.

Hope this helps
mlmcc
0
 

Author Comment

by:marksmall
ID: 6974735
first of all mlmcc , your code that you specified works ok, but i tried to add this code below it to check if BOTH Delete and Write access is selected but it will not work!

Else
                        If DeleteAccess = True And WriteAccess = True Then
                        cmdDelete.Visible = True
                        cmdUpdate.Visible = True
                        cmdNew.Visible = True
                        Call UnlockRecords
                        lblAdminNotice.Caption = "Read, Write, Update, Delete access!"
                        lblAdminNotice.Visible = True


here is what i am trying to do!


if Admin is selected then that user has BOTH Delete and Write access and other stuff (Don't need to worry about that in this form!)

if write access is seletced then all buttons are shown EXCEPT the delete one (cmdDelete)

if delete access is selected then all buttons are hiden EXCEPT the delete one (cmdDelete)

if BOTH delete access and write access are selected then ALL buttons are shown! (this is where i am having the PROBLEM!)

0
 
LVL 100

Accepted Solution

by:
mlmcc earned 50 total points
ID: 6975010
The problem is that if both write and delete are selected then with the way the code is written, the WriteAccess test is true and no further tests are done.  

Since a user can have both write and delete access (the options aren't mutually exclusive).  It appears having both delete and write access is the same as having only delete
Tests should be done in this order
  ADMIN permissions?  'Most powerful user
  DELETE & WRITE permissions? 'same as DELETE only
  DELETE permissions?  'Only need this or the above
  WRITE permissions?
  ELSE READONLY      'Least powerful user

try this

Function AllowAccess()

    If IsAdmin = True Then
      cmdDelete.Visible = True
      cmdUpdate.Visible = True
      cmdNew.Visible = True
      Call UnlockRecords
      lblNotice.Caption = "Administrator Access, Read, Write, Delete!"
      lblNotice.Visible = True

     Else If DeleteAccess = True Then
          cmdDelete.Visible = True
          cmdUpdate.Visible = True
          cmdNew.Visible = True
          Call UnlockRecords
          lblNotice.Caption = "Read, Write, Update, Delete access!"
          lblNotice.Visible = True

    Else If WriteAccess = True Then
         cmdDelete.Visible = False
         cmdUpdate.Visible = True
         cmdNew.Visible = True
         Call UnlockRecords
         lblNotice.Caption = "Read, Write, Update access!"
         lblNotice.Visible = True

     Else
         cmdDelete.Visible = False
         cmdUpdate.Visible = False
         cmdNew.Visible = False
         Call LockRecords
         lblNotice.Caption = "Read Access Only!"
         lblNotice.Visible = True

    End If

Hope this solves it.
mlmcc
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7670335
Hi marksmall,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept mlmcc's comment(s) as an answer.

marksmall, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Expert Comment

by:Computer101
ID: 8095635
Comment from expert accepted as answer

Computer101
E-E Admin
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now