Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

code problem

Posted on 2002-04-27
10
Medium Priority
?
164 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 101

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
LVL 101

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 101

Accepted Solution

by:
mlmcc earned 200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

824 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