login form help required

V

vandy

Hi All,

I am attempting to create my own security login screen and not use Security
Wizard

I have a table
Authorization

id- Autonumber-pk
UserID - username
Pwd - password
Level - number

Based on the level of the user the forms should be read only or full access.

I have designed a login screen with the follwoing code:

Private Sub btnlogin_Click()

Dim qplevel As Variant
If IsNull(Me.quserid) Then
MsgBox ("You Must Enter a Valid User ID !!")
Exit Sub
Else
If IsNull(Me.qpwd) Then
MsgBox ("You Must Enter a Password!!")
Exit Sub
End If
End If

If Me.qpwd.Value = DLookup("PWD", "Authorized", "UserID ='" &
Me.quserid.Value & "'") Then
DoCmd.OpenForm "MainMenu", acNormal
Else
MsgBox ("Invalid Password!Try Again!")
End If
qplevel = DLookup("[Level]", "Authorized", "[UserID] = '" & Me.quserid.Value
& "'")

If qplevel >= 2 Then
MsgBox ("Read only access")
DoCmd.OpenForm "q10"
DoCmd.OpenForm "transactionfrm", , , , acFormReadOnly
'Me.AllowEdits = False
'Me.AllowDeletions = False
'Me.AllowAdditions = False
Else
MsgBox ("full access")
'Me.AllowEdits = True
'Me.AllowDeletions = True
'Me.AllowAdditions = True
End If
End Sub

I know that to enable or disable a form you can set the AllowEdits to true
or false but how or were should i use this.
I want to be able to contol the way forms are opened. Right now the
condition is working and i am getting the correct messages but how to
selectively open the form in read only and give selective controls on some
controls on the form.

Thanks for your patience. I would appreciate your inputs and help.
 
J

JimS

Try...

OpenArgs... Look 'em up in the help system. You set openargs when you use
the docmd.openform to open the form. One of its arguments is a text field
called openargs. Then in form open event handler of your newly opened form
("q10"?), you can set allowedits, etc. as you desire.

Public Variable, or better yet, Public function. Set up a public variable
or function whose result is the user's authority level. Then every form
examines the result of that function on open to decide if it should be
read-only or all-access. It only takes a couple lines of VBA code in the open
event handler of each form...

Either one works. I use both.
 
V

vandy

Thanks for your reply. I think declaring Public variables and opening each
form using the users authority level will work.

I think that there should be a case statment that says case full users :
allow edit = true else read only users " allow edits = false.

I should pass the numeric value of the authority level in my form and it
would open based on the user level.

Can you give me an example code for this to work. should i have a seperate
module declared to have the public variables declared and to define the
users.

How using code can i open a form passing the authority level.

I am not very good in VB coding and would greatly appreciate the help
provided.

thanks


JimS said:
Try...

OpenArgs... Look 'em up in the help system. You set openargs when you use
the docmd.openform to open the form. One of its arguments is a text field
called openargs. Then in form open event handler of your newly opened form
("q10"?), you can set allowedits, etc. as you desire.

Public Variable, or better yet, Public function. Set up a public variable
or function whose result is the user's authority level. Then every form
examines the result of that function on open to decide if it should be
read-only or all-access. It only takes a couple lines of VBA code in the open
event handler of each form...

Either one works. I use both.

--
Jim


vandy said:
Hi All,

I am attempting to create my own security login screen and not use Security
Wizard

I have a table
Authorization

id- Autonumber-pk
UserID - username
Pwd - password
Level - number

Based on the level of the user the forms should be read only or full access.

I have designed a login screen with the follwoing code:

Private Sub btnlogin_Click()

Dim qplevel As Variant
If IsNull(Me.quserid) Then
MsgBox ("You Must Enter a Valid User ID !!")
Exit Sub
Else
If IsNull(Me.qpwd) Then
MsgBox ("You Must Enter a Password!!")
Exit Sub
End If
End If

If Me.qpwd.Value = DLookup("PWD", "Authorized", "UserID ='" &
Me.quserid.Value & "'") Then
DoCmd.OpenForm "MainMenu", acNormal
Else
MsgBox ("Invalid Password!Try Again!")
End If
qplevel = DLookup("[Level]", "Authorized", "[UserID] = '" & Me.quserid.Value
& "'")

If qplevel >= 2 Then
MsgBox ("Read only access")
DoCmd.OpenForm "q10"
DoCmd.OpenForm "transactionfrm", , , , acFormReadOnly
'Me.AllowEdits = False
'Me.AllowDeletions = False
'Me.AllowAdditions = False
Else
MsgBox ("full access")
'Me.AllowEdits = True
'Me.AllowDeletions = True
'Me.AllowAdditions = True
End If
End Sub

I know that to enable or disable a form you can set the AllowEdits to true
or false but how or were should i use this.
I want to be able to contol the way forms are opened. Right now the
condition is working and i am getting the correct messages but how to
selectively open the form in read only and give selective controls on some
controls on the form.

Thanks for your patience. I would appreciate your inputs and help.
 
J

JimS

First, let me say to all those reading this, you would be best using a
"class" module to do this, but it's a little hard to understand for a
beginner.

I have a form called "frmStartUp" that opens automatically on startup and
asks the user to authenticate. Put the authentication code in a "module" as
shown. Then call the procedure "getAuthLevel" from your startup form. You
already know how to do the authentication.
----------------------------

Declare your public variable in a "module" (called say, "Utilities"):

Option Explicit
Public AuthLevel as Integer

Public Procedure GetAuthLevel ()
{Put your code here to authenticate the user}
...
...
AuthLevel = {the authorization Level you derived above} 'This sets it
permanently (for this run)

End Sub

-----------------------

Then, you can put the following code in every form. As you create the form,
go to the event "On Open", and tell it to use a Procedure. It will take you
to vba, creating the procedure "shell" for you.

Private Sub Form_Open(Cancel As Integer)
Select nz(AuthLevel,0) 'The "nz" function deals with the possibility
that you may not have authenticated this user
Case 0
Cancel = True 'Closes the form immediately with no message
Case 1
me.allow......
Case 2
me.allow.....
Case else
Cancel = True
End Select

End Sub
--
Jim





vandy said:
Thanks for your reply. I think declaring Public variables and opening each
form using the users authority level will work.

I think that there should be a case statment that says case full users :
allow edit = true else read only users " allow edits = false.

I should pass the numeric value of the authority level in my form and it
would open based on the user level.

Can you give me an example code for this to work. should i have a seperate
module declared to have the public variables declared and to define the
users.

How using code can i open a form passing the authority level.

I am not very good in VB coding and would greatly appreciate the help
provided.

thanks


JimS said:
Try...

OpenArgs... Look 'em up in the help system. You set openargs when you use
the docmd.openform to open the form. One of its arguments is a text field
called openargs. Then in form open event handler of your newly opened form
("q10"?), you can set allowedits, etc. as you desire.

Public Variable, or better yet, Public function. Set up a public variable
or function whose result is the user's authority level. Then every form
examines the result of that function on open to decide if it should be
read-only or all-access. It only takes a couple lines of VBA code in the open
event handler of each form...

Either one works. I use both.

--
Jim


vandy said:
Hi All,

I am attempting to create my own security login screen and not use Security
Wizard

I have a table
Authorization

id- Autonumber-pk
UserID - username
Pwd - password
Level - number

Based on the level of the user the forms should be read only or full access.

I have designed a login screen with the follwoing code:

Private Sub btnlogin_Click()

Dim qplevel As Variant
If IsNull(Me.quserid) Then
MsgBox ("You Must Enter a Valid User ID !!")
Exit Sub
Else
If IsNull(Me.qpwd) Then
MsgBox ("You Must Enter a Password!!")
Exit Sub
End If
End If

If Me.qpwd.Value = DLookup("PWD", "Authorized", "UserID ='" &
Me.quserid.Value & "'") Then
DoCmd.OpenForm "MainMenu", acNormal
Else
MsgBox ("Invalid Password!Try Again!")
End If
qplevel = DLookup("[Level]", "Authorized", "[UserID] = '" & Me.quserid.Value
& "'")

If qplevel >= 2 Then
MsgBox ("Read only access")
DoCmd.OpenForm "q10"
DoCmd.OpenForm "transactionfrm", , , , acFormReadOnly
'Me.AllowEdits = False
'Me.AllowDeletions = False
'Me.AllowAdditions = False
Else
MsgBox ("full access")
'Me.AllowEdits = True
'Me.AllowDeletions = True
'Me.AllowAdditions = True
End If
End Sub

I know that to enable or disable a form you can set the AllowEdits to true
or false but how or were should i use this.
I want to be able to contol the way forms are opened. Right now the
condition is working and i am getting the correct messages but how to
selectively open the form in read only and give selective controls on some
controls on the form.

Thanks for your patience. I would appreciate your inputs and help.
 
V

vandy

Thanks JimS for your input. I am trying out what you suggested but seem to
struggle in a particular code.

This is the code I added in the open event of a form. here i call Utilities
which is the module i created.

Private Sub Form_Open(Cancel As Integer)
Call Utilities
Select Case Nz(AuthLevel, 0)
Case 0
Cancel = True
Case 2
Me.AllowEdits = False
Me.AllowDeletions = False
Me.AllowAdditions = False
Case 1
Me.AllowEdits = True
Me.AllowDeletions = True
Me.AllowAdditions = True
Case Else
Cancel = True
End Select
End Sub

Is this what is should in every form to bring user level control.


Module Utilities

Option Compare Database

Option Explicit
Public AuthLevel As Integer


Public Sub GetAuthLevel()

AuthLevel = DLookup("[Level]", "Authorized", "[UserID] = '" &
Me.quserid.Value & "'")

If AuthLevel >= 2 Then
MsgBox ("Read only access")
Else
MsgBox ("full access")
End If
AuthLevel = 2
End Sub

Question: How do i read the authoriztion level from the table and check for
the value in the module.

When you say authorization code you must mean

Private Sub btnlogin_Click()

Dim qplevel As Variant

If IsNull(Me.quserid) Then
MsgBox ("You Must Enter a Valid User ID !!")
Exit Sub
Else
If IsNull(Me.qpwd) Then
MsgBox ("You Must Enter a Password!!")
Exit Sub
End If
End If

If Me.qpwd.Value = DLookup("PWD", "Authorized", "UserID ='" &
Me.quserid.Value & "'") Then
MsgBox ("Welcome")
Else
MsgBox ("Invalid Password!Try Again!")
End If
End Sub

This code is in my login form and triggered in the login button click event.
How to code the Utilities module code and call it in the login startup form.
I have been helped this far and would appreciate your help and patience in
solving this code.


Thanks in advance as always.

JimS said:
First, let me say to all those reading this, you would be best using a
"class" module to do this, but it's a little hard to understand for a
beginner.

I have a form called "frmStartUp" that opens automatically on startup and
asks the user to authenticate. Put the authentication code in a "module" as
shown. Then call the procedure "getAuthLevel" from your startup form. You
already know how to do the authentication.
----------------------------

Declare your public variable in a "module" (called say, "Utilities"):

Option Explicit
Public AuthLevel as Integer

Public Procedure GetAuthLevel ()
{Put your code here to authenticate the user}
...
...
AuthLevel = {the authorization Level you derived above} 'This sets it
permanently (for this run)

End Sub

-----------------------

Then, you can put the following code in every form. As you create the form,
go to the event "On Open", and tell it to use a Procedure. It will take you
to vba, creating the procedure "shell" for you.

Private Sub Form_Open(Cancel As Integer)
Select nz(AuthLevel,0) 'The "nz" function deals with the possibility
that you may not have authenticated this user
Case 0
Cancel = True 'Closes the form immediately with no message
Case 1
me.allow......
Case 2
me.allow.....
Case else
Cancel = True
End Select

End Sub
--
Jim





vandy said:
Thanks for your reply. I think declaring Public variables and opening each
form using the users authority level will work.

I think that there should be a case statment that says case full users :
allow edit = true else read only users " allow edits = false.

I should pass the numeric value of the authority level in my form and it
would open based on the user level.

Can you give me an example code for this to work. should i have a seperate
module declared to have the public variables declared and to define the
users.

How using code can i open a form passing the authority level.

I am not very good in VB coding and would greatly appreciate the help
provided.

thanks


JimS said:
Try...

OpenArgs... Look 'em up in the help system. You set openargs when you use
the docmd.openform to open the form. One of its arguments is a text field
called openargs. Then in form open event handler of your newly opened form
("q10"?), you can set allowedits, etc. as you desire.

Public Variable, or better yet, Public function. Set up a public variable
or function whose result is the user's authority level. Then every form
examines the result of that function on open to decide if it should be
read-only or all-access. It only takes a couple lines of VBA code in the open
event handler of each form...

Either one works. I use both.

--
Jim


:

Hi All,

I am attempting to create my own security login screen and not use Security
Wizard

I have a table
Authorization

id- Autonumber-pk
UserID - username
Pwd - password
Level - number

Based on the level of the user the forms should be read only or full access.

I have designed a login screen with the follwoing code:

Private Sub btnlogin_Click()

Dim qplevel As Variant
If IsNull(Me.quserid) Then
MsgBox ("You Must Enter a Valid User ID !!")
Exit Sub
Else
If IsNull(Me.qpwd) Then
MsgBox ("You Must Enter a Password!!")
Exit Sub
End If
End If

If Me.qpwd.Value = DLookup("PWD", "Authorized", "UserID ='" &
Me.quserid.Value & "'") Then
DoCmd.OpenForm "MainMenu", acNormal
Else
MsgBox ("Invalid Password!Try Again!")
End If
qplevel = DLookup("[Level]", "Authorized", "[UserID] = '" & Me.quserid.Value
& "'")

If qplevel >= 2 Then
MsgBox ("Read only access")
DoCmd.OpenForm "q10"
DoCmd.OpenForm "transactionfrm", , , , acFormReadOnly
'Me.AllowEdits = False
'Me.AllowDeletions = False
'Me.AllowAdditions = False
Else
MsgBox ("full access")
'Me.AllowEdits = True
'Me.AllowDeletions = True
'Me.AllowAdditions = True
End If
End Sub

I know that to enable or disable a form you can set the AllowEdits to true
or false but how or were should i use this.
I want to be able to contol the way forms are opened. Right now the
condition is working and i am getting the correct messages but how to
selectively open the form in read only and give selective controls on some
controls on the form.

Thanks for your patience. I would appreciate your inputs and help.
 
J

JimS

The module "Utilities" should contain the following code:

Option Compare Database
Option Explicit
Public AuthLevel As Integer 'This variable remains available throughout
your db once set

Public Sub SetAuthLevel(strUserID As String)
If IsNull(strUserID) Then
AuthLevel = 0 'If the subroutine is called with a null string,
return 0
Exit Sub
End If

'Assumes you have a table called "Authorized"
' with columns "UserID" (string) and "Level" (integer);
'NZ() Sets AuthLevel to zero if not found
AuthLevel = Nz(DLookup("[Level]", "Authorized", "[UserID]= '" &
strUserID & "'"), 0) End Sub

-----------

Your opening form should ask the user for his ID, probably stored in a text
box (say, "tbUserID"). When the user has entered his userID, execute the
following:

Call SetAuthLevel(tbUserID.value)


Then the routine you showed (Form_Open) is fine, except remove the "Call
Utilities" line. Put that routine in every form where you want to set the
AllowDeletions, etc. properties.
--
Jim


vandy said:
Thanks JimS for your input. I am trying out what you suggested but seem to
struggle in a particular code.

This is the code I added in the open event of a form. here i call Utilities
which is the module i created.

Private Sub Form_Open(Cancel As Integer)
Call Utilities
Select Case Nz(AuthLevel, 0)
Case 0
Cancel = True
Case 2
Me.AllowEdits = False
Me.AllowDeletions = False
Me.AllowAdditions = False
Case 1
Me.AllowEdits = True
Me.AllowDeletions = True
Me.AllowAdditions = True
Case Else
Cancel = True
End Select
End Sub

Is this what is should in every form to bring user level control.


Module Utilities

Option Compare Database

Option Explicit
Public AuthLevel As Integer


Public Sub GetAuthLevel()

AuthLevel = DLookup("[Level]", "Authorized", "[UserID] = '" &
Me.quserid.Value & "'")

If AuthLevel >= 2 Then
MsgBox ("Read only access")
Else
MsgBox ("full access")
End If
AuthLevel = 2
End Sub

Question: How do i read the authoriztion level from the table and check for
the value in the module.

When you say authorization code you must mean

Private Sub btnlogin_Click()

Dim qplevel As Variant

If IsNull(Me.quserid) Then
MsgBox ("You Must Enter a Valid User ID !!")
Exit Sub
Else
If IsNull(Me.qpwd) Then
MsgBox ("You Must Enter a Password!!")
Exit Sub
End If
End If

If Me.qpwd.Value = DLookup("PWD", "Authorized", "UserID ='" &
Me.quserid.Value & "'") Then
MsgBox ("Welcome")
Else
MsgBox ("Invalid Password!Try Again!")
End If
End Sub

This code is in my login form and triggered in the login button click event.
How to code the Utilities module code and call it in the login startup form.
I have been helped this far and would appreciate your help and patience in
solving this code.


Thanks in advance as always.

JimS said:
First, let me say to all those reading this, you would be best using a
"class" module to do this, but it's a little hard to understand for a
beginner.

I have a form called "frmStartUp" that opens automatically on startup and
asks the user to authenticate. Put the authentication code in a "module" as
shown. Then call the procedure "getAuthLevel" from your startup form. You
already know how to do the authentication.
----------------------------

Declare your public variable in a "module" (called say, "Utilities"):

Option Explicit
Public AuthLevel as Integer

Public Procedure GetAuthLevel ()
{Put your code here to authenticate the user}
...
...
AuthLevel = {the authorization Level you derived above} 'This sets it
permanently (for this run)

End Sub

-----------------------

Then, you can put the following code in every form. As you create the form,
go to the event "On Open", and tell it to use a Procedure. It will take you
to vba, creating the procedure "shell" for you.

Private Sub Form_Open(Cancel As Integer)
Select nz(AuthLevel,0) 'The "nz" function deals with the possibility
that you may not have authenticated this user
Case 0
Cancel = True 'Closes the form immediately with no message
Case 1
me.allow......
Case 2
me.allow.....
Case else
Cancel = True
End Select

End Sub
--
Jim





vandy said:
Thanks for your reply. I think declaring Public variables and opening each
form using the users authority level will work.

I think that there should be a case statment that says case full users :
allow edit = true else read only users " allow edits = false.

I should pass the numeric value of the authority level in my form and it
would open based on the user level.

Can you give me an example code for this to work. should i have a seperate
module declared to have the public variables declared and to define the
users.

How using code can i open a form passing the authority level.

I am not very good in VB coding and would greatly appreciate the help
provided.

thanks


:

Try...

OpenArgs... Look 'em up in the help system. You set openargs when you use
the docmd.openform to open the form. One of its arguments is a text field
called openargs. Then in form open event handler of your newly opened form
("q10"?), you can set allowedits, etc. as you desire.

Public Variable, or better yet, Public function. Set up a public variable
or function whose result is the user's authority level. Then every form
examines the result of that function on open to decide if it should be
read-only or all-access. It only takes a couple lines of VBA code in the open
event handler of each form...

Either one works. I use both.

--
Jim


:

Hi All,

I am attempting to create my own security login screen and not use Security
Wizard

I have a table
Authorization

id- Autonumber-pk
UserID - username
Pwd - password
Level - number

Based on the level of the user the forms should be read only or full access.

I have designed a login screen with the follwoing code:

Private Sub btnlogin_Click()

Dim qplevel As Variant
If IsNull(Me.quserid) Then
MsgBox ("You Must Enter a Valid User ID !!")
Exit Sub
Else
If IsNull(Me.qpwd) Then
MsgBox ("You Must Enter a Password!!")
Exit Sub
End If
End If

If Me.qpwd.Value = DLookup("PWD", "Authorized", "UserID ='" &
Me.quserid.Value & "'") Then
DoCmd.OpenForm "MainMenu", acNormal
Else
MsgBox ("Invalid Password!Try Again!")
End If
qplevel = DLookup("[Level]", "Authorized", "[UserID] = '" & Me.quserid.Value
& "'")

If qplevel >= 2 Then
MsgBox ("Read only access")
DoCmd.OpenForm "q10"
DoCmd.OpenForm "transactionfrm", , , , acFormReadOnly
'Me.AllowEdits = False
'Me.AllowDeletions = False
'Me.AllowAdditions = False
Else
MsgBox ("full access")
'Me.AllowEdits = True
'Me.AllowDeletions = True
'Me.AllowAdditions = True
End If
End Sub

I know that to enable or disable a form you can set the AllowEdits to true
or false but how or were should i use this.
I want to be able to contol the way forms are opened. Right now the
condition is working and i am getting the correct messages but how to
selectively open the form in read only and give selective controls on some
controls on the form.

Thanks for your patience. I would appreciate your inputs and help.
 
V

vandy

Thanks Jims,

The code worked like a charm and i can control the entire form or elements
in the form. Thanks for your help , patience and guidance.


JimS said:
The module "Utilities" should contain the following code:

Option Compare Database
Option Explicit
Public AuthLevel As Integer 'This variable remains available throughout
your db once set

Public Sub SetAuthLevel(strUserID As String)
If IsNull(strUserID) Then
AuthLevel = 0 'If the subroutine is called with a null string,
return 0
Exit Sub
End If

'Assumes you have a table called "Authorized"
' with columns "UserID" (string) and "Level" (integer);
'NZ() Sets AuthLevel to zero if not found
AuthLevel = Nz(DLookup("[Level]", "Authorized", "[UserID]= '" &
strUserID & "'"), 0) End Sub

-----------

Your opening form should ask the user for his ID, probably stored in a text
box (say, "tbUserID"). When the user has entered his userID, execute the
following:

Call SetAuthLevel(tbUserID.value)


Then the routine you showed (Form_Open) is fine, except remove the "Call
Utilities" line. Put that routine in every form where you want to set the
AllowDeletions, etc. properties.
--
Jim


vandy said:
Thanks JimS for your input. I am trying out what you suggested but seem to
struggle in a particular code.

This is the code I added in the open event of a form. here i call Utilities
which is the module i created.

Private Sub Form_Open(Cancel As Integer)
Call Utilities
Select Case Nz(AuthLevel, 0)
Case 0
Cancel = True
Case 2
Me.AllowEdits = False
Me.AllowDeletions = False
Me.AllowAdditions = False
Case 1
Me.AllowEdits = True
Me.AllowDeletions = True
Me.AllowAdditions = True
Case Else
Cancel = True
End Select
End Sub

Is this what is should in every form to bring user level control.


Module Utilities

Option Compare Database

Option Explicit
Public AuthLevel As Integer


Public Sub GetAuthLevel()

AuthLevel = DLookup("[Level]", "Authorized", "[UserID] = '" &
Me.quserid.Value & "'")

If AuthLevel >= 2 Then
MsgBox ("Read only access")
Else
MsgBox ("full access")
End If
AuthLevel = 2
End Sub

Question: How do i read the authoriztion level from the table and check for
the value in the module.

When you say authorization code you must mean

Private Sub btnlogin_Click()

Dim qplevel As Variant

If IsNull(Me.quserid) Then
MsgBox ("You Must Enter a Valid User ID !!")
Exit Sub
Else
If IsNull(Me.qpwd) Then
MsgBox ("You Must Enter a Password!!")
Exit Sub
End If
End If

If Me.qpwd.Value = DLookup("PWD", "Authorized", "UserID ='" &
Me.quserid.Value & "'") Then
MsgBox ("Welcome")
Else
MsgBox ("Invalid Password!Try Again!")
End If
End Sub

This code is in my login form and triggered in the login button click event.
How to code the Utilities module code and call it in the login startup form.
I have been helped this far and would appreciate your help and patience in
solving this code.


Thanks in advance as always.

JimS said:
First, let me say to all those reading this, you would be best using a
"class" module to do this, but it's a little hard to understand for a
beginner.

I have a form called "frmStartUp" that opens automatically on startup and
asks the user to authenticate. Put the authentication code in a "module" as
shown. Then call the procedure "getAuthLevel" from your startup form. You
already know how to do the authentication.
----------------------------

Declare your public variable in a "module" (called say, "Utilities"):

Option Explicit
Public AuthLevel as Integer

Public Procedure GetAuthLevel ()
{Put your code here to authenticate the user}
...
...
AuthLevel = {the authorization Level you derived above} 'This sets it
permanently (for this run)

End Sub

-----------------------

Then, you can put the following code in every form. As you create the form,
go to the event "On Open", and tell it to use a Procedure. It will take you
to vba, creating the procedure "shell" for you.

Private Sub Form_Open(Cancel As Integer)
Select nz(AuthLevel,0) 'The "nz" function deals with the possibility
that you may not have authenticated this user
Case 0
Cancel = True 'Closes the form immediately with no message
Case 1
me.allow......
Case 2
me.allow.....
Case else
Cancel = True
End Select

End Sub
--
Jim





:

Thanks for your reply. I think declaring Public variables and opening each
form using the users authority level will work.

I think that there should be a case statment that says case full users :
allow edit = true else read only users " allow edits = false.

I should pass the numeric value of the authority level in my form and it
would open based on the user level.

Can you give me an example code for this to work. should i have a seperate
module declared to have the public variables declared and to define the
users.

How using code can i open a form passing the authority level.

I am not very good in VB coding and would greatly appreciate the help
provided.

thanks


:

Try...

OpenArgs... Look 'em up in the help system. You set openargs when you use
the docmd.openform to open the form. One of its arguments is a text field
called openargs. Then in form open event handler of your newly opened form
("q10"?), you can set allowedits, etc. as you desire.

Public Variable, or better yet, Public function. Set up a public variable
or function whose result is the user's authority level. Then every form
examines the result of that function on open to decide if it should be
read-only or all-access. It only takes a couple lines of VBA code in the open
event handler of each form...

Either one works. I use both.

--
Jim


:

Hi All,

I am attempting to create my own security login screen and not use Security
Wizard

I have a table
Authorization

id- Autonumber-pk
UserID - username
Pwd - password
Level - number

Based on the level of the user the forms should be read only or full access.

I have designed a login screen with the follwoing code:

Private Sub btnlogin_Click()

Dim qplevel As Variant
If IsNull(Me.quserid) Then
MsgBox ("You Must Enter a Valid User ID !!")
Exit Sub
Else
If IsNull(Me.qpwd) Then
MsgBox ("You Must Enter a Password!!")
Exit Sub
End If
End If

If Me.qpwd.Value = DLookup("PWD", "Authorized", "UserID ='" &
Me.quserid.Value & "'") Then
DoCmd.OpenForm "MainMenu", acNormal
Else
MsgBox ("Invalid Password!Try Again!")
End If
qplevel = DLookup("[Level]", "Authorized", "[UserID] = '" & Me.quserid.Value
& "'")

If qplevel >= 2 Then
MsgBox ("Read only access")
DoCmd.OpenForm "q10"
DoCmd.OpenForm "transactionfrm", , , , acFormReadOnly
'Me.AllowEdits = False
'Me.AllowDeletions = False
'Me.AllowAdditions = False
Else
MsgBox ("full access")
'Me.AllowEdits = True
'Me.AllowDeletions = True
'Me.AllowAdditions = True
End If
End Sub

I know that to enable or disable a form you can set the AllowEdits to true
or false but how or were should i use this.
I want to be able to contol the way forms are opened. Right now the
condition is working and i am getting the correct messages but how to
selectively open the form in read only and give selective controls on some
controls on the form.

Thanks for your patience. I would appreciate your inputs and help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top