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!

Setting password for all restricted forms

Status
Not open for further replies.

jac123

Technical User
Apr 25, 2003
19
US

I have set up my database with several forms that can be viewed but no changes can be made on them. In order for the user to make changes, they need to select an Add/Edit button on the toolbar, which opens a restricted dialog box, asking the user for his password. When the correct password is given, an Edit form opens, where the user can add or edit the DB. Below is the code I placed in the Load form of each of the Edit forms.
What I want to be able to do on my “Introduction” form, which only appears the first time the user opens the DB, is to set the “password” the user types in.
From my reading, sounds as though I need to create a Module to run from the introduction form. I have never created a Module. Any help would be greatly appreciated.
I have looked thru the examples, and am not able to find anything on this subject. Perhaps, I’m not typing in the
appropriate words.


Private Sub Form_Load()
Dim strPasswd
Dim BaptismEdit As Form

strPasswd = InputBox("Enter Password", "Restricted Form")

If strPasswd = "" Or strPasswd = Empty Then
MsgBox "No Input Provided", vbInformation, "Required Data"
DoCmd.Close acForm, "Baptism Edit"
Exit Sub
End If

If strPasswd = "Morton" Then
DoCmd.OpenForm "Baptism Edit", acNormal
Else
MsgBox "Sorry, you do not have access to this form", vbOKOnly, _
"Important Information"
DoCmd.Close acForm, "Baptism Edit"
Exit Sub
End If
End Sub

 

Any time you write code, you're doing it in a module. The only difference is that you've been using the Form's module. You can write Public functions and subroutines in a separate module and access them simply by making a call to them. Something like this in the form's module...
Code:
Private Sub cmdYourButton()
   ProcessSomething  [COLOR=green]'the name of a Public Sub[/color]
End Sub
With this in the module...
Code:
Public Sub ProcessSomething()
   [i]place code here[/i]
End Sub

If you want a value returned, use a public Function.
Code:
Private Sub cmdAnotherButton()
   Dim intResponse as Integer
   intResponse = Call MyPercentage(txtNumber)
End Sub
Code:
Public Function MyPercentage(txtNumber As Integer) As Integer
   MyCalculation = txtNumber * .5
End Function

For your password situation....
By using an input box, you leave your user open to the possibility of someone observing him/her typing in the password. I'd suggest creating a separate table that contains, at a minimum, passwords. Then create a form to be used instead of the input box. The password would be typed into a textbox on the form. Set the Input Mask property of the textbox to Password, which will cause the display to show only *****'s. You can also set the Input Mask of the field in the table to Password.

Randy
 
Randy
Thank you for your response. I will continue to work on
this with your suggestions.

Jeanne
 
. . . and here's sample code you can use once you get it setup:
Code:
[blue]   Dim PWD As String
   Dim Msg As String, Style As Integer, Title As String, DL As String
   
   DL = vbNewLine & vbNewLine
   PWD = Trim(Me!PwdTextboxName & "")
   
   If PWD = "" Or PWD <> "Morton" Then
      Msg = "No input or wrong password provided!" & DL & _
            "Permission to open form denied!"
      Style = vbInformation + vbOKOnly
      Title = "Password Error! . . ."
      MsgBox Msg, Style, Title
   Else
      DoCmd.OpenForm "Baptism Edit", acNormal
   End If[/blue]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top