Help to use AllowAdditions, AllowDeletions and AllowEdits

Dear friends,

Please, I want to use AllowAdditions, AllowDeletions and AllowEdits for a form of mine, but I just don't

know how to create a VB code to do it.

Here's my case...
I have a form I use to enter the username and his password, I'm gonna call it "frmlogon".

The frmlogon has:

- a combobox with a dropdown to choose a username;
- a textbox for the password input;
- when i press enter it verifies the username/password confirmation and then opens the MainForm (if password matches, offcourse! If not, there's a MsgBox for it.)

I've already done this! It's working pretty fine! The point is... Each username has a kind of "permission" to handle the MainForm.
i have a table named "tblUsers"
uUserID      uFirstName      uLastName      uPassword      uSecurityID
1      reception            ***      1
3      ADMIN            ***      9
6      security            ***      1
so if you please i want
Users with uSecurityID 1 - Can add only
Users with uSecurityID 9 - Can add and edit and delete.
Users with uSecurityID 8 - Can add only
or any other way regardless the uSecurityID
How do I do that? I've seen something like this...
If intUserID = 1 Then
Me.Form.AllowAdditions = True
Me.Form.AllowDeletions = True
Me.Form.AllowEdits = True
ElseIf intUserID = 2 Then
Me.Form.AllowAdditions = True
Me.Form.AllowDeletions = True
Me.Form.AllowEdits = False

But I confess, I didn't understand how to use it, how to design the code structure.
Please, if someone could help me, I would really appreciate it.
i attached the database and the password for any user is 123
Thanks everyone for your attention.
security-database-test.accdb
hassan momoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PatHartmanCommented:
You may have a typo in your description of what 1 and 8 do so be sure to check what I have done for sanity.  Setting the AllowAdditions and AllowDeletions doesn't present any problem but the AllowEdits does since it also locks buttons and prevents the use of search boxes if you have any so I've included the method I use that locks (or unlocks) individual controls.

Start with code in the form's Load event to set the "Allow" properties  These apply to all records and so should be set as the form loads.
Then the form's Current event runs for each new record.  This event runs once for each record and you use it to set properties that affect only the current record.

The LockControls sub needs to go into a standard module - NOT IN YOUR FORM's class module.  That way, it will be available for use from ALL forms.  It makes use of each control's Tag property to override the lock/unlock setting.  For example, a control that shows the record's autonumber primary key should always be locked and therefore, I set it's Tag property to "Lock".  A search field that allows you to go to a different record should always be unlocked so the Tag property should be "NoLock" because you want to be able to use the field to find records regardless of whether or not the user can update or delete them.  Most buttons should also be set to "NoLock".  You'll need to decide individually if a control needs to be overridden.  Remember, the Tag is only used for special controls where you want them to be locked or unlocked regardless of the user's permissions.

You will need to customize the Load and Current functions to reflect your actual security needs but the LockControls sub can be copied as is.
Private Sub Form_Load()
    Select Case Forms!frmLogin!uSecurityID
        Case 1
            Me.AllowAdditions = True
        Case 9 
            Me.AllowAdditions = True
            Me.AllowDeletions = True
        Case Else
            Me.AllowAdditions = False
            Me.AllowDeletions = False
    End Select
End Sub

Private Sub Form_Current()

    Select Case Forms!frmLogin!uSecurityID
        Case 1
            If Me.NewRecord = True Then
                Call LockControls(Me, False)        'unlock
            Else
                Call LockControls(Me, True)	    'lock
	    End If
        Case 8, 9 
            Call LockControls(Me, False)        'unlock
        Case Else
            Call LockControls(Me, True)        'lock
        
    End Select

End Sub

Open in new window

Public Sub LockControls(frm As Form, bLock As Boolean)
    Dim ctl As Control
    For Each ctl In frm.Controls
    Select Case ctl.ControlType
        Case acTextBox, acComboBox, acListBox, acCheckBox
            Select Case ctl.Tag
                Case "NoLock"
                    ctl.Locked = False
                Case "Lock"
                    ctl.Locked = True
                Case Else
                    ctl.Locked = bLock         'toggle locks
            End Select
        Case acCommandButton
            Select Case ctl.Tag
                Case "NoLock"
                    ctl.Enabled = True
                Case "Lock"
                    ctl.Enabled = False
                Case Else
                    ctl.Enabled = Not bLock         'toggle locks
            End Select
    End Select
Next ctl
Set ctl = Nothing
End Sub   

Open in new window

1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hassan momoAuthor Commented:
thank you a lot for your reply but when i use the above code for add or deletions in Form_Load event for login form or any sub form i got error. any ideas
0
PatHartmanCommented:
It works for me.  Please post your code.
0
hassan momoAuthor Commented:
when i put the code and open the form it give me run-time error when i press debug it highlights this codewhen i put the code and open the form it give me run-time error when i press debug it highlights this code
0
PatHartmanCommented:
I guessed at the name of your login form.  If you examine the highlighted line, you will see that the form name I chose is different from your actual form name.  Change that line of code to match your form name and your control name.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.