Page 1 of 5 12345 LastLast
Results 1 to 15 of 66
  1. #1
    Sheba is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    239

    Question forms - Accesslevel

    I have AccesslevelID and CategoryID as foreign keys in my user table.

    Administrator has Level 1
    Data Entry has level 4
    Reader has level 3
    Each form has a unique category ID

    On my login form, my combobox User ID has it's row source, as this query:
    SELECT userID, LName & "," & FName AS FullName, Password, AccessLevelID, CategoryID


    FROM tblUser
    ORDER BY LName, FName;


    I don't want the DataEntry user to be able to delete records. But the code below is allowing them to. Could someone advise what is wrong with it please

    Code:
    If Forms!frmLogin!cmbUser.Column(3) = 4 Then
        If Forms!frmLogin!cmbUser.Column(4) = "OB01" Then
            With Me
                .DataEntry = True
                .AllowEdits = True
                .AllowDeletions = False
                .AllowAdditions = True
                .AllowFilters = True
            End With
        Else
            MsgBox "You are not authorized to view this form"
            Cancel = True
            DoCmd.Close acForm, "ObstetricsForm", acSaveNo
        End If
    Else
        If Forms!frmLogin!cmbUser.Column(3) = "All" Then
            If Forms!frmLogin!cmbUser.Column(4) = 1 Then
                With Me
                    .DataEntry = True
                    .AllowEdits = True
                    .AllowDeletions = True
                    .AllowAdditions = True
                    .AllowFilters = True
                End With
            Else
                With Me
                    .DataEntry = False
                    .AllowEdits = True
                    .AllowDeletions = False
                    .AllowAdditions = False
                    .AllowFilters = True
                End With
            End If
        End If
    End If

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Use code tags when posting code and the indentation will be preserved and make it easier to read. I edited your post to show that.

    Have you step debugged? Review link at bottom of my post for debugging guidelines.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I have AccesslevelID and CategoryID as foreign keys in my user table.
    So you should have a table "AccessLevels"? What is it structure? (field names and types)

    Cutting out a lot of code, you have:
    Code:
    If Forms!frmLogin!cmbUser.Column(3) = 4 Then  '<<= this is a NUMBER
        If Forms!frmLogin!cmbUser.Column(4) = "OB01" Then  '<<= this is TEXT
    .
    .
        End If
    Else
        If Forms!frmLogin!cmbUser.Column(3) = "All" Then  '<<= this is TEXT
            If Forms!frmLogin!cmbUser.Column(4) = 1 Then   '<<= this is  a NUMBER
    .
    .
    .
    What are the field types in table "tblUser" for the fields "AccessLevelID" and "CategoryID"??

  4. #4
    Sheba is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    239
    Hi June7 and Steve, thanks for your responses. My AccessLevel has only two columns ID (autonumber datatype) and level(text).
    The category table also has two columns ID(text datatype) and Name(text)

    In the User table AccessLevel has Number data type and Category has Text data type

  5. #5
    Sheba is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    239
    Forgot to add: Thanks June7 for editing my post for me. Certainly looks better this way and yes, I'd step debugged it yesterday and today again.

  6. #6
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    A couple of things worth mentioning. You should NOT have a combo for the user, it gives anyone trying to crack your db half of the information.
    It would also be easier to use a yes/no field for the security level.

    HTH

  7. #7
    Sheba is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    239
    thanks burrina. you're correct that is why I took out the "Remember Password" box. For now, it is being tested but I'll work on changing the combo box to a text box

  8. #8
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    So you see that both tests here should be numeric:
    Code:
    If Forms!frmLogin!cmbUser.Column(3) = 4 Then  '<<= this is a NUMBER
    Else
        If Forms!frmLogin!cmbUser.Column(3) = "All" Then  '<<= this is TEXT

    and both tests here should be Text??
    Code:
        If Forms!frmLogin!cmbUser.Column(4) = "OB01" Then  '<<= this is TEXT
    
            If Forms!frmLogin!cmbUser.Column(4) = 1 Then   '<<= this is  a NUMBER



    If there is an entry in the tblCategory.CategoryID field that is a 1, you could use
    Code:
    If Forms!frmLogin!cmbUser.Column(4) = "1" Then   '<<= this is  a NUMBER

  9. #9
    Sheba is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    239
    hey Steve, sorry I'm a bit confused here. Currently there is nothing in the Category table which has a "1". I guess from you've said, changing the category ID (field and data type) to 'Number' is the way to go?

    Basically the IF statements should have the same data type for their criteria?

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Steve is pointing out inconsistency in your code.

    In one place Column(3) is compared to a text parameter - "All".
    In another place Column(3) is compared to a number parameter - 4.

    In one place Column(4) is compared to a text parameter - "OB01".
    In another place Column(4) is compared to a number parameter - 1.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    Sheba is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    239

    Question

    hi June7. I hadn't picked up on that. Funny, in my program I have the correct columns referenced (as per below). I think after pasting the code yesterday, I must have made that change. Although the correct column references exist on my form, the code is still allowing the user to delete the record

    If Forms!frmLogin!cmbUser.Column(3) = 4 Then
    If Forms!frmLogin!cmbUser.Column(4) = "OB01" Then
    With Me
    .DataEntry = True
    .AllowEdits = True
    .AllowDeletions = False
    .AllowAdditions = True
    .AllowFilters = True
    End With
    Else
    MsgBox "You are not authorized to view this form"
    Cancel = True
    DoCmd.Close acForm, "ObstetricsForm", acSaveNo
    End If
    Else
    If Forms!frmLogin!cmbUser.Column(4) = "All" Then
    If Forms!frmLogin!cmbUser.Column(3)= 1 Then
    With Me
    .DataEntry = True
    .AllowEdits = True
    .AllowDeletions = True
    .AllowAdditions = True
    .AllowFilters = True
    End With
    ..
    End If
    End If

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Step debug, follow the code as it executes. Determine why it deviates from expected behavior. Fix code and repeat.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  13. #13
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    As June said, write down what conditions you require, then single step through the code watching the variables in the code.

    I have two monitors - the form in the left and the code in the right monitor. So easy

  14. #14
    Sheba is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    239
    Thanks June7 and Steve. In my code, both references to column(3) have numeric data type while references to column(4) have text data type. I Step debugged did but it does not highlight any code for correction hence my confoundment

  15. #15
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    As has been suggested, you have to refer to matching data types, numbers to numbers and text to text. Is this the case?
    References start at 0 for the Column count!

Page 1 of 5 12345 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 10-23-2013, 08:11 AM
  2. Replies: 5
    Last Post: 01-16-2013, 03:48 PM
  3. Multiple forms or embedded sub-forms
    By Juicejam in forum Forms
    Replies: 2
    Last Post: 08-23-2011, 07:31 AM
  4. Replies: 1
    Last Post: 01-04-2011, 05:04 AM
  5. Replies: 4
    Last Post: 04-01-2009, 08:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums