How to use AllowAdditions, AllowDeletions and AllowEdits?

brunces

Registered User.
Local time
Today, 17:23
Joined
Sep 12, 2004
Messages
45
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 which is opened only before a password confirmation. I'm gonna call it "MainForm". And the

form I use to enter the username and his password, I'm gonna call it "LoginForm".

The LoginForm has:

- a combobox with a dropdown to choose a username;
- a textbox for the password input;
- a button (ENTER) which 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. For example:

There are only 5 users...

User1 - Can add, delete and edit.
User2 - Can add and delete.
User3 - Can add and edit.
User4 - Can delete and edit.
User5 - Can edit.

So, here's my doubt. When I click the button ENTER, in the LoginForm, besides checking username and

password, I want it to open the MainForm with those permissions allowed or not, depending on the user who

logged in.

How do I do that? I've seen something like this...

(... more code above)
If intUserID = 1 Then
With frm
.AllowAdditions = False
.AllowDeletions = False
.AllowEdits = False
End With
Else
With frm
.AllowAdditions = True
.AllowDeletions = True
.AllowEdits = True
End With
End If
(... more code below)

But I confess, I didn't understand how to use it, how to design the code structure. In other words, I really

don't know how to create a VB code for that. Where would I put this code? Would it be part of the "OnClick

Event" for the button ENTER (LoginForm) or part of the "Sub Form_Open()" of the MainForm? Should I use

"Select Case" instead of "If...Then...Else" in the code? Whatever...

Please, if someone could help me, I would really appreciate it. :)

Thanks everyone for your attention.

Hugz.

Bruno

Obs.: For particular reasons, I don't use the Users/Group Security Accounts provided by MS Access.
 
The code needs to be in the forms OnOpen event. Not sure if there is an easier way to do this but this will work...
Code:
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open
    
    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
    ElseIf intUserID = 3 Then
        Me.Form.AllowAdditions = True
        Me.Form.AllowDeletions = False
        Me.Form.AllowEdits = False
    ElseIf intUserID = 4 Then
        Me.Form.AllowAdditions = False
        Me.Form.AllowDeletions = True
        Me.Form.AllowEdits = False
    ElseIf intUserID = 5 Then
        Me.Form.AllowAdditions = False
        Me.Form.AllowDeletions = False
        Me.Form.AllowEdits = True
    Else
        Me.Form.AllowAdditions = False
        Me.Form.AllowDeletions = False
        Me.Form.AllowEdits = False
    End If
    
Exit_Form_Open:
    Exit Sub
    
Err_Form_Open:
    MsgBox Err.Number & " - " & Err.Description
    Resume Exit_Form_Open
    
End Sub
 
Thank you very much!!!

ghudson,

Hi. It really worked very well and I'm here to thank you very much for your attention.

Hugz, pal.

Bruno
 

Users who are viewing this thread

Back
Top Bottom