Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Security / February 2005

Tip: Looking for answers? Try searching our database.

Exit Password Prompt Option

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kyle Friesen - 25 Feb 2005 17:03 GMT
Hello,

I have a password protected form that is working great thanks Access
Monster and MSN help. However, one missing piece that I tried to figure out
is that I want to add a exit option to the password form. Basically for
users that didn't intend on opening the password protected form.

here is the code I have for the Null value notification. Can I add some
sort of If IsNull then CloseForm line instead of the "try again"?  

Any sort of attempt brings up "Invalid use of Null" error message that may
confuse users.

****
Private Sub CheckPassword_Click()
If IsNull(Forms!frmPassword!Text0.Value) Then
               MsgBox "You Must Enter A Password. Try Again."
               Me!Text0.SetFocus
     
           Else
                MyPassword = Me!Text0.Value
                DoCmd.Close acForm, "frmPassword"
           End If
End Sub
****

Thanks!
Jeff Conrad - 25 Feb 2005 19:37 GMT
> I have a password protected form that is working great thanks Access
> Monster and MSN help. However, one missing piece that I tried to figure out
[quoted text clipped - 19 lines]
> End Sub
> ****

Before I offer some suggestions, can you first verify something for me?
Is your form and code based on these KB articles?

http://support.microsoft.com/?id=209871
http://support.microsoft.com/?id=179371

If so, have you followed them to the letter or have you made modifications?

Signature

Jeff Conrad
Access Junkie
Bend, Oregon

Kyle Friesen - 25 Feb 2005 19:51 GMT
yes, exactly those articles.

I have a main form that everyone may access and at the bottom left corner
of the main form a open frm command button that executes the frmpassword
procedure (restricted form).

I want to add an exit button option on the frmpassword.

thanks, Jeff.

Kyle
Jeff Conrad - 25 Feb 2005 20:16 GMT
> yes, exactly those articles.
>
[quoted text clipped - 5 lines]
>
> thanks, Jeff.

I just added a new command button onto frmPassword called
cmdExit with the following code in the Click event:

Private Sub cmdExit_Click()
   DoCmd.Close acForm, "frmPassword"
End Sub

I put a Caption of Cancel, but you can use whatever you would like.

Hitting the Exit button will, however, still cause the calling form
to pop up the message box about incorrect password. Everything
worked just fine in my test.

If you would like to not show the "Incorrect Password" message box
when a user presses the Exit button on the frmPassword then let
me know. I have a solution for that as well. I would need to know
if you have made ANY changes to the Form_Open event code.

Signature

Jeff Conrad
Access Junkie
Bend, Oregon

Kyle Friesen - 25 Feb 2005 20:19 GMT
Jeff,
yes, I would like to close the form without a password error message and I
have not made any changes to the on open procedure. thanks for your help.
Jeff Conrad - 25 Feb 2005 20:37 GMT
> Jeff,
> yes, I would like to close the form without a password error message and I
> have not made any changes to the on open procedure. thanks for your help.

Okie Dokie.

Follow these steps:

1. Make a couple backup copies of your database first

2. Open the frmPassword and change the Exit command button
Click event code to this:

Private Sub cmdExit_Click()
   MyPassword = "ExitButton"
   DoCmd.Close acForm, "frmPassword"
End Sub

3. Save and close that form

4. Open one of the forms that you are password protecting.
Go to the code window behind this form and look for the Open
event code. It should be exactly like the KB article code.
Look for this area of the code:

  On Error GoTo Error_Handler
  ' Prompt the user for the Password.
  DoCmd.OpenForm "frmPassword", acNormal, , , , acDialog
           Hold = MyPassword

' Open the table that contains the password.
  Set db = CurrentDb
   ....yadda....yadda....

In between those two areas we will add a few more lines of code.
It should now look like this:

  On Error GoTo Error_Handler
  ' Prompt the user for the Password.
  DoCmd.OpenForm "frmPassword", acNormal, , , , acDialog
           Hold = MyPassword

   ' User pressed exit button so skip everything else
   If Hold = "ExitButton" Then
       Cancel = True
       Exit Sub
   End If

' Open the table that contains the password.
  Set db = CurrentDb
   ....yadda....yadda....

What this will do is tell Access to cancel opening the protected form,
but not display anything since the rest of the code procedure is just
skipped.

You will need to enter the same code in the same spot for any other
forms or reports you are password protecting. Also, do NOT use
ExitButton as a password for any of the forms and reports.

Everything works fine in my tests.
Hope that helps,
Signature

Jeff Conrad
Access Junkie
Bend, Oregon

Kyle Friesen - 25 Feb 2005 20:59 GMT
great! thanks. one more quick one for you, Jeff.

Now I am getting a VB Error  "The OpenForm action was canceled".

The form being the password protected object. Any ideas on how to elimate
that error message too?
Kyle Friesen - 25 Feb 2005 21:13 GMT
Jeff, I changed the command button's on click from an event procedure to a
macro and turned the warnings off.

everything works fine now, thanks for your help.

Kyle
Jeff Conrad - 25 Feb 2005 21:43 GMT
> Jeff, I changed the command button's on click from an event procedure to a
> macro and turned the warnings off.
>
> everything works fine now, thanks for your help.

While the macro will work Kyle, I would not recommend it.
The macro could by chance encounter other error messages
which would cause Access to cough up a "Halt" hair ball.
I would suggest just trapping and ignoring the error as I
outlined in my other post.

Signature

Jeff Conrad
Access Junkie
Bend, Oregon

Jeff Conrad - 25 Feb 2005 21:21 GMT
> great! thanks. one more quick one for you, Jeff.
>
> Now I am getting a VB Error  "The OpenForm action was canceled".
>
> The form being the password protected object. Any ideas on how to elimate
> that error message too?

Yep, easy to fix.

Error 2501 is the one you are encountering and it is the standard Access
message for this type of thing. The error is actually occurring on the main
form, not the protected one or frmPassword. You said you had a main
form that you users clicked to open the protected form. That main form
is the one you need to open in Design View and go to the code for
the click event of the button that opens the protected form.

We need to add some error handling to this click event. Most likely there
probably already is some error handling code. You just need to ignore
Error 2501. You will have to modify this example code for your situation:

Private Sub cmdOpenForm_Click()
On Error GoTo ErrorPoint

   DoCmd.OpenForm "ProtectedFormNameHere"

ExitPoint:
   Exit Sub

ErrorPoint:
   If err.Number <> 2501 Then
       ' Unexpected Error
       MsgBox "The following error has occurred:" _
       & vbNewLine & "Error Number: " & err.Number _
       & vbNewLine & "Error Description: " & err.Description _
       , vbExclamation, "Unexpected Error"
   End If
   Resume ExitPoint

End Sub

If you still have problems adapting this into your code, just post
all the code behind the click event for that main form button and
I will make the modifications for you.

Signature

Jeff Conrad
Access Junkie
Bend, Oregon

Kyle Friesen - 25 Feb 2005 19:58 GMT
jeff, I have followed those articles exactly, just want to add a feature
which allows users to exit the frmpassword. thanks.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.