Hello,
I have two users in my database.
Users : ABC and XYZ.
In attached pic I want that if I login as a XYZ then command 7 and 8 should be disabled.
What will be the procedure?
Thanks.
Hello,
I have two users in my database.
Users : ABC and XYZ.
In attached pic I want that if I login as a XYZ then command 7 and 8 should be disabled.
What will be the procedure?
Thanks.
Only two users for this db?
One way:
Me.Command7.Visible = User = "ABC"
Me.Command8.Visible = User = "ABC"
How and where do you set variable User? This could be a textbox on a form that never closes (I do this - MainMenu never closes). Or can be a global variable - global variables are a nuisance when debugging. Do users login with username and password? Is this a split db? Is backend on a network server?
There are ways to make this more dynamic and allow for more users. Involves use of a UserInfo table. Can use intrinsic function Envriron() to get username from the network. Syntax:
Environ("USERNAME") - yes, type EXACTLY as shown. Access does not recognize Environ() but VBA does.
Then use that value to match record in table. Table can have field for user permissions (admin, manager, staff). Set control visibility based on permissions.
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.
Yes June, the users will select their user names and enter passwords.
then they will go inside database.
Right now this is a simple database.This is not a split database nor backend on server.
This is my coding for users login Command.
Option Compare Database
Option Explicit
Dim intLogonAttempts As Integer
Private Sub cboemployee_AfterUpdate()
'After selecting user name set focus to password field
Me.TXTPASSWORD.SetFocus
End Sub
Private Sub cmdlogin_Click()
'Check to see if data is entered into the UserName combo box
If IsNull(Me.cboemployee) Or Me.cboemployee = "" Then
MsgBox "Please Enter User Name", vbOKOnly, "Required Data"
Me.cboemployee.SetFocus
Exit Sub
End If
'Check to see if data is entered into the password box
If IsNull(Me.TXTPASSWORD) Or Me.TXTPASSWORD = "" Then
MsgBox "Please Enter Your Password", vbOKOnly, "Required Data"
Me.TXTPASSWORD.SetFocus
Exit Sub
End If
'Check value of password in tblEmployees to see if this
'matches value chosen in combo box
If Me.TXTPASSWORD.Value = DLookup("strEmpPassword", "tblEmployees", _
"[lngEmpID]=" & Me.cboemployee.Value) Then
lngMyEmpID = Me.cboemployee.Value
'Close logon form and open splash screen
DoCmd.OpenForm "SWITCHBOARD"
DoCmd.Close acForm, "logon", acSavePrompt
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
"Invalid Entry!"
Me.TXTPASSWORD.SetFocus
End If
'If User Enters incorrect password 3 times database will shutdown
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database.Please contact admin.", _
vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub
How do you want to hold the username after login? Do you want to populate a textbox on SWITCHBOARD? One method could be to bind the SWITCHBOARD form to Users table. Then use WHERE CONDITION of OpenForm to filter SWITCHBOARD recordset.
DoCmd.OpenForm "SWITCHBOARD", , , "USERNAME='" & Me.USERNAME & "'"
Bind a textbox on SWITCHBOARD to USERNAME field.
Then code in any form can refer to the SWITCHBOARD (as long as it never closes) for criteria.
If Forms!SWITCHBOARD.USERNAME = "ABC" Then
...
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.
Hello June,
In attached image there is my user name table and switchboad.
I want that if user is abc then command7 should not be visible or not enabled.
so tell me procedure for this.
Secondly in future may be I will share this database on server but now I am using this database only on my system with two users.
Did you bind SWITCHBOARD to Users table?
Do you have code in the login form to open filtered SWITCHBOARD?
If yesses then code in SWITCHBOARD Open event:
If Me!strempname = "abc" Then Me.Command7.Visible = False
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.
No I did not bind s.board with users table.
how to bind?
No I don't have any code in login form for filtered s.board.
all the code in user form is as I mentioned in post no. 3
Bind form by setting RecordSource property. Basic Access functionality for building forms. Access Help has guidance.
If you want to try the described method, then follow instructions given for coding. Test, debug, fix errors, repeat. Refer to link at bottom of my post for debug techniques.
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.
Ohh sorry I was forgot about binding.
Now I binded switch board with user table.
I changed the login code like this:
'Close logon form and open splash screen
DoCmd.OpenForm "SWITCHBOARD", , , "strempname='" & Me.strempname & "'"
so login form will not close after login.
I bound one text box on switchboard with user names.
I put this code on switchboard open event:
If Me!strempname = "abc" Then Me.Command7.Visible = False
what I do now?
Thanks
Why won't login form close? You show code in procedure to close the form.
Is suggested code working? If so, then your issue is resolved. I don't know what you want to do beyond that.
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.
I remove this line from coding
DoCmd.Close acForm, "logon", acSavePrompt
bcoz as you said in post no.4
I want to code on login form which will never close.Then code in any form can refer to the SWITCHBOARD (as long as it never closes) for criteria.
Did you misread my statement?
I said the SWITCHBOARD form should never close, not the Login form.
If you want to do something different from my suggestion then explain what you want.
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.
Ohh yes sorry I misread your statement.
yes I did as you said but now the problem is the text box which I bound with user name on switchboard.
if I login as xyz or abc there is always showing xyz and secondly command7 is also always visible.
Is strempname a field or control name on the login form? I can't tell from your code.
What control on login form has the username? That is the control to reference in the code that opens SWITCHBOARD.
Do you want to provide db for analysis? Follow instructions at bottom of my post.
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.
OK thanks.
tomorrow I will try myself if I didn't solve then I will provide db.