Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programming read only

Status
Not open for further replies.

bigdrewecu

Programmer
Apr 20, 2004
14
US
ok i have it to where a form starts and the user enters a password which works fine however depending on the user i want to make certain forms read only and others dataentry.
i figured if i coded the first form to store the users name in a global variable and then do an if statement on the form load event with using:
If strUserName = "businessmanager" Then
Me.AllowAdditions = True
Me.AllowDeletions = True
Me.AllowEdits = True
Me.DataEntry = True
ElseIf strUserName = "Admin" Then
Me.AllowAdditions = True
Me.AllowDeletions = True
Me.AllowEdits = True
Me.DataEntry = True
Else
Me.AllowAdditions = False
Me.AllowDeletions = False
Me.AllowEdits = False
Me.DataEntry = False
End If

but for some odd reason it is not working and evaluating to where i can not edit, add new records etc when i log in as admin or businessmanager. any boday have any solutions?
 
My first question is how you defined and populated the global variable.

Secondly, instead of a cascading if-then-else, I think you'd be far better off using a case statement
Code:
Select Case strUserName
   Case "businessmanager"
      Me.AllowAdditions = True
      ...
   Case "Admin"
      ...
   Case Else
      ....
End Select
I would also ensure that you are not running into case sensitivity issues.

Good Luck
--------------
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
ok well i defined it as a string and im pulling it from a textbox off a form that the user will enter in
 
Private Sub cmdOk_Click()
Dim count As Integer
If txtUsername = "businessmanager" Then
If txtpswd = "vddgna" Then
strUserName = txtUsername
Form_Startup.Visible = False
Form_Switchboard.Visible = True


Else
MsgBox ("Invalid Password")
txtpswd.Text = ""
txtpswd.SetFocus


End If
count = count + 1
If count >= 3 Then
MsgBox ("You will be logged off due to number of incorrect entries")
Form_Startup.Application.CloseCurrentDatabase
count = 0
End If
End If
If txtUsername = "Admin" Then
If txtpswd = "ciscobud" Then
Form_Startup.Visible = False
Form_Switchboard.Visible = True
Else
MsgBox ("Invalid Password")
txtpswd.SetFocus
count = count + 1
If count > 3 Then
MsgBox ("You will be logged off due to number of incorrect entries")
Form_Startup.Application.CloseCurrentDatabase
Form_Startup.DataEntry = True
count = 0
End If
End If
End If
If txtUsername = "guest" Then

Form_Startup.Visible = False
Form_Switchboard.Visible = True
strUserName = txtUsername

End If

End Sub
 
But where did you define it? If you defined it in the declarations section of a form, then it is not a global variable, it is a public property of that form, and can be referenced outside of that form with a fully qualified Form reference.

However, if you define it in the declarations section of a standard code module, then it will be a global variable.

Good Luck
--------------
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
It also appears that you are not assigning it a value when an Admin logs on.

Good Luck
--------------
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
defined it in a module and i fixed the asigning value.....but for some reason it evaulates to case else which would be where it is just read only
 
Check case sensitivity.
"Admin" will not = "admin"
I would assign it to all upper case
strUserName = UCase(txtUsername)
and then use all upper case in the case statement.

Good Luck
--------------
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
It may also useful to ask why you are re-inventing the (security) wheel? Ms. A. has a reasonably robust security system, which is aready built in and ALWAYS in use, it just needs configuring to accomodate your needs.

One possiblie issue with your choice of user name (Admin) is that it is the default username for an "unsecured" MS. A. app. The Global variable "username" is provides throught all Ms. A. apps, with the default for (unsecured/un-configured) apps as "Admin".




MichaelRed
mlred@verizon.net

 
How are you ensuring that a valid user name is entered?

Good Luck
--------------
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top