Results 1 to 12 of 12
  1. #1
    Join Date
    Nov 2004
    Location
    Crick, just outside Rugby
    Posts
    42

    Red face Unanswered: Password protect one form

    Hi,

    I have a database which is available for everyone to view (but not modify). I have one form to enable data add/edit which I want to password protect rather than setting up user accounts and access rights.
    So only those authorised to edit/add can get to that form.
    I have a main menu with a command button to open it - is the button protected or the form?

    Can someone give me a bit of advice.

    Thanks

    Sherri

  2. #2
    Join Date
    Jan 2004
    Location
    Aberdeen, Scotland
    Posts
    1,067
    If it was me doing this id open a seperate form for your password on the click of your button on the main form, when the user inputs the correct password then you can then proceed to your protected form, but thats just me

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    I'd do both
    If someone can view the database then they can open the form, so you probably need to put some code into the forms "on open" event and chuck 'em out if not authenticated. I often also set whether the usergroup is allowd to add,edit, change or delete in the "on open" event. The alternative is to set the workgrop permisions so that users cannot read the design of the forms

    As a design stylistic I'd disable the button unless they can use the button (and therefore view the form).

  4. #4
    Join Date
    Nov 2004
    Posts
    64
    try this piece of code in your "on open" property for the form you are trying to protect

    'Private Sub Form_Open(Cancel As Integer)
    Dim x As String
    x = "password"
    Dim y As String
    y = InputBox("Enter Password for form")
    If x <> y Then
    MsgBox "wrong Password"
    DoCmd.Close
    Else
    End If
    'End Sub


    Cheers
    Peter.t

  5. #5
    Join Date
    Nov 2004
    Location
    Crick, just outside Rugby
    Posts
    42
    Thanks Peter,

    That's just what I wanted.
    It is only to stop someone accidently deleting information. The information isn't top secret or anything.

    It works a treat.

    Thanks

  6. #6
    Join Date
    Nov 2004
    Location
    Crick, just outside Rugby
    Posts
    42
    Ooops!

    One small problem!!
    If you cancel the password box, or enter the wrong password and click OK to close the 'wrong password' message box , it opens the form anyway.

    What am I missing?

    Thanks

    Sherri

  7. #7
    Join Date
    Jan 2004
    Location
    Aberdeen, Scotland
    Posts
    1,067
    After your If
    Put the Line
    Cancel = True in this will cancel the action thats about to take place

    edited due to me speaking rubbish
    Last edited by DavidCoutts; 11-26-04 at 09:24.

  8. #8
    Join Date
    Nov 2004
    Posts
    64
    Hi
    I have just checked it on my computer , it is working fine, the important part of the code to prevent the form from staying open is the DoCmd.Close check that is correct.
    if you want to have the password on a command button on another form then the code would be like this
    Private Sub cmdopenform_Click()
    Dim x As String
    x = "password"
    Dim y As String
    y = InputBox("Enter Password for form")
    If x <> y Then
    MsgBox "wrong Password"
    Exit Sub ' wrong password take no further action exit
    Else 'Password is correct continue to open the form
    Dim stDocName As String
    stDocName = "YourFormName"
    DoCmd.OpenForm stDocName
    End If
    End Sub

    cheers
    Peter
    Last edited by Peter.t; 11-26-04 at 09:19.

  9. #9
    Join Date
    Nov 2004
    Location
    Crick, just outside Rugby
    Posts
    42
    Hi,

    After adding the 'Cancel=True' to the 'OnOpen' part of the form, if I cancelled or password was incorrect, it would close my menu form.

    So I tried the password on the button and it works fine.

    Thank you Peter & David for your help.

    You have always got a solution for me - it's great!

  10. #10
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Don't forget that a user can also load the form directly (from the database dialog), without going through your switchboard or menu.

    So I'd also put some validation in the forms "open" event, it can refer to the password control on, or variable in the calling form, and if not found cancel the form load.

    eg
    private sub form_open(cancel as integer)
    if forms!<parentform>!<controlsource> <> vbtrue then
    cancel=true
    exit sub
    endif

    this assumes that
    <controlsource> has been set if the password is OK
    so if the parent form was called mainmenu the controlsource was IsValid then

    Private Sub Form_Open(Cancel As Integer)
    on error goto cancelload
    if forms!mainfrorm!isvalid <> vbtrue then
    cancel=true
    exit sub
    endif
    on error resume next
    exit sub
    cancelload: 'the main reason for geting here is if an error has occured
    'likely candidates are the calling form isn't loaded
    cancel=true
    End Sub

  11. #11
    Join Date
    Mar 2004
    Location
    Oakland, CA, USA
    Posts
    26
    Hello I'mSherriToo,

    Remember to make your database as MDE file and keep the MDB file as a master backup in case you need modify it. That way no one could mess around with your form design. Since most access beginer know how go to Design the Code of the form then they will get the password easily.

  12. #12
    Join Date
    Nov 2004
    Location
    Crick, just outside Rugby
    Posts
    42
    Ok,

    Thanks for the advice.... I will look deeper into it.

    Cheers

    Sherri

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •