step1:- add a table named users with 3 fields named:- username,password,accesstype
fill username ,password of your choice and in access type fill 1 and 2.
for example:-
UserName Password AccessType
admin admin 1
regular regular 2
step 2:- create a module named intialization in modules, then open it and paste this code
Public Function InitApp()
AllowSpecialKeys = False
DoCmd.SelectObject acTable, , True
DoCmd.RunCommand acCmdWindowHide
DoCmd.ShowToolbar "Database", acToolbarNo
Application.CommandBars("SALES SYSTEM MENU").Enabled = False
Application.SetOption "Enable MRU File List", False
Application.SetOption "Built-In Toolbars Available", False
End Function
step 3 :- add a form named login form, then in autoexe macro first write an action runcode, give function name initapp(). now write action open form
and give the login form name.
step 4 :- in login form's design view add two text boxes , one for username and another for password and add one command button named login
step 5:- right clk on login button and clk properties, now move to event tab, there choose on clk event and write event procedure in it. now clk it vb code window will open , paste this code in it.
Private Sub cmdLogin_Click()
If IsNull(Me.UserName) Or Me.UserName = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.UserName.SetFocus
Exit Sub
End If
If IsNull(Me.password) Or Me.password = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.password.SetFocus
Exit Sub
End If
Dim access
access = DLookup("AccessType", "Users", "[UserName]='" & Me.UserName.Value & "' And [Password]='" & Me.password.Value & "'")
If access = 1 Then
Application.SetOption "Built-In Toolbars Available", True
DoCmd.RunMacro "ADMIN LOGIN", , ""
DoCmd.ShowToolbar "Database", acToolbarYes
DoCmd.SelectObject acTable, , True
Application.CommandBars("SALES SYSTEM MENU").Enabled = True
Application.SetOption "Can Customize Toolbars", True
Application.SetOption "Control Wizards", True
ElseIf access = 2 Then
DoCmd.RunMacro "ADMIN LOGIN", , ""
DoCmd.ShowToolbar "Database", acToolbarYes
DoCmd.SelectObject acTable, , True
DoCmd.RunCommand acCmdWindowHide
Application.CommandBars("SALES SYSTEM MENU").Enabled = True
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.password.SetFocus
End If
End Sub
step 6:- only thing that u have to do is just how to merge these macro in your application. be carefull regarding sequence of execution starting from autoexe macro.
This code is 100% working in my application.
for any more query you can e-mail me on akhil.chopra@live.com.
fill username ,password of your choice and in access type fill 1 and 2.
for example:-
UserName Password AccessType
admin admin 1
regular regular 2
step 2:- create a module named intialization in modules, then open it and paste this code
Public Function InitApp()
AllowSpecialKeys = False
DoCmd.SelectObject acTable, , True
DoCmd.RunCommand acCmdWindowHide
DoCmd.ShowToolbar "Database", acToolbarNo
Application.CommandBars("SALES SYSTEM MENU").Enabled = False
Application.SetOption "Enable MRU File List", False
Application.SetOption "Built-In Toolbars Available", False
End Function
step 3 :- add a form named login form, then in autoexe macro first write an action runcode, give function name initapp(). now write action open form
and give the login form name.
step 4 :- in login form's design view add two text boxes , one for username and another for password and add one command button named login
step 5:- right clk on login button and clk properties, now move to event tab, there choose on clk event and write event procedure in it. now clk it vb code window will open , paste this code in it.
Private Sub cmdLogin_Click()
If IsNull(Me.UserName) Or Me.UserName = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.UserName.SetFocus
Exit Sub
End If
If IsNull(Me.password) Or Me.password = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.password.SetFocus
Exit Sub
End If
Dim access
access = DLookup("AccessType", "Users", "[UserName]='" & Me.UserName.Value & "' And [Password]='" & Me.password.Value & "'")
If access = 1 Then
Application.SetOption "Built-In Toolbars Available", True
DoCmd.RunMacro "ADMIN LOGIN", , ""
DoCmd.ShowToolbar "Database", acToolbarYes
DoCmd.SelectObject acTable, , True
Application.CommandBars("SALES SYSTEM MENU").Enabled = True
Application.SetOption "Can Customize Toolbars", True
Application.SetOption "Control Wizards", True
ElseIf access = 2 Then
DoCmd.RunMacro "ADMIN LOGIN", , ""
DoCmd.ShowToolbar "Database", acToolbarYes
DoCmd.SelectObject acTable, , True
DoCmd.RunCommand acCmdWindowHide
Application.CommandBars("SALES SYSTEM MENU").Enabled = True
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.password.SetFocus
End If
End Sub
step 6:- only thing that u have to do is just how to merge these macro in your application. be carefull regarding sequence of execution starting from autoexe macro.
This code is 100% working in my application.
for any more query you can e-mail me on akhil.chopra@live.com.
