Solved

MSAccess Password Form - Auto close when entered

Posted on 2011-09-29
15
342 Views
Last Modified: 2012-05-12
I am trying to get a form to open up at the start of a report run, and after the user enters their password, get it to close.  I've tried using the "AfterUpdate" event, and even tried using a command button On_Click event.  But it just sits open until I manually close with the MS Close (upper-right corner).

Private Sub cmdEnter_Enter()
    Forms!frmReportGenerator!txtACSPswd = Me.txtEnterPswd
   ' Forms!frmACSPswd!txtEnterPswd.SetFocus
    DoCmd.Close acForm, "Forms!frmACSPswd", acSaveNo
End Sub

Private Sub txtEnterPswd_AfterUpdate()
    Forms!frmReportGenerator!txtACSPswd = Me.txtEnterPswd
    DoCmd.Close acForm, "Forms!frmACSPswd", acSaveNo

End Sub

Open in new window

Password-Form.mdb
0
Comment
Question by:Lambel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
  • 3
15 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 36817885
So you are not validating this password, just opening the report?

Then do this on the "Click" event of the button:

Private Sub cmdEnter_Click()
DoCmd.OpenReport "YourReport", acViewPreview
DoCmd.Close acForm, Me.Name
End Sub
0
 
LVL 14

Expert Comment

by:pteranodon72
ID: 36817920
Lambel,

The command to close should be:

DoCmd.Close acForm, "frmACSPswd", acSaveNo

Just remove the Forms! part.
After_update only fires if the form is bound to a recordsource (table or query). I'm guessing it is not. You could use txtEnterPswd_LostFocus() That would fire after TAB, ENTER, or clicking another control on the form.


HTH,

pT72
0
 

Author Comment

by:Lambel
ID: 36817985
pteranodon72: I get a runtime error 2585 : This action can't be carried out while processing a form or report event.

Does it matter that I am starting up a process to run some reports?  It is about the third function that runs before I try to make a connection to the ACS database.
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 14

Expert Comment

by:pteranodon72
ID: 36818241
I hadn't realized it, but forms can't be closed during the got/lost focus or enter/exit events of controls. I spoke too soon on that one. Since the form is unbound, there is no After_Update or Form_Current that would uniquely identify filling of the the field. I would use a command button's OnClick event. Also, boag2000's use of

DoCmd.Close acForm, Me.Name

Means that you don't have to hard-code the name of the form into the code. You can change the Form's name without causing errors.

pT72
0
 
LVL 14

Expert Comment

by:pteranodon72
ID: 36818252
That error was not due to your report process -- it was just running the close action from within LostFocus.

boag2000 had the right answer from the start!

pT72
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 36819163
pT72,

Yeah, I just posted what I thought the OP wanted based on the very basic sample file.

Just a guess really....

Let's see what the OP comes back with...

Jeff
0
 

Author Comment

by:Lambel
ID: 36892085
boag2000: Tried this, but the form just sits there.  And the program pauses, waiting for the form to close. When I close with the MS Close the program runs successfully.

Private Sub cmdEnter_Click()
    Forms!frmReportGenerator!txtACSPswd = Me.txtEnterPswd
    DoCmd.Close acForm, "Forms!frmACSPswd", acSaveNo
End Sub
0
 
LVL 14

Expert Comment

by:pteranodon72
ID: 36892488
(no points wanted)
I think you just need to change the second argument to:
to:

DoCmd.Close acForm, "frmACSPswd", acSaveNo

or

DoCmd.Close acForm, Me.Name, acSaveNo

The second one, as boag2000 suggested, holds up if you change the name of the form.

HTH,
pT72
0
 

Author Comment

by:Lambel
ID: 36893767
<sigh>  It's still not working(?!?)
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 36893904
It is not clear what you are trying to do or how your forms are set up.
How many forms?
The *EXACT* sequence of events you want to happen, ...etc

It is also not clear if there is anything else involved in this issue...

Can you simply post a sample DB to avoid confusion?

Sample database notes:
1. Back up your database(s).
2. Combine the front and back ends into one database file.
3. Remove any startup options, unless they are relevant to the issue.
4. Remove any records unless they are relevant to the issue.
5. Delete any objects that do not relate directly to the issue.
6. Remove any references to any "linked" files (files outside of the database, Images, OLE Files, ...etc)
7. Remove any references to any third party Active-x Controls (unless they are relevant to the issue)
8. Remove, obfuscate, encrypt, or otherwise disguise, any sensitive data.
9. Compile the code. (From the VBA code window, click: Debug-->Compile)
10. Run the compact/Repair utility.
11. Remove any Passwords and/or security.
12. If a form is involved in the issue, set the Modal and Popup properties to: No
    (Again, unless these properties are associated with the issue)
13. Post the explicit steps to replicate the issue.
14. Test the database before posting.

In other words, ...post a database that we can easily open and immediately see and/or troubleshoot the issue.
And if applicable, also include a clear graphical representation of the *Exact* results you are expecting, based on the sample data.

JeffCoachman
0
 

Author Comment

by:Lambel
ID: 36931415
I have stripped down my db file to only the first 2 tabs of the form, and the password form and attached it below.  When a user clicks the "Run Report" button on the report form (frmReportGenerator), I want the password dialog to open.  The user enters their password, clicks the enter button, and the password is passed to a hidden textfield on frmReportGenerator called txtACSPswd, where I can reference it later from other processes, including the report run.  After the user clicks the "Enter" button on the password form, I want it to close, and the "run report" process to continue.

Let me know if you need anything else.
Thanks, Lynn Password-Form.zip Password-Form.zip
0
 
LVL 14

Expert Comment

by:pteranodon72
ID: 36934696
Ah! I can see the confusion now. Thanks for posting this!

Replace the line

'current
DoCmd.Close acForm, "Me.frmACSPassword", acSaveNo

Open in new window


with either
'exact name of form in quotes
DoCmd.Close acForm, "frmACSPassword", acSaveNo

Open in new window


or

'reference to the current form's Name property (no quotes)
DoCmd.Close acForm, Me.Name, acSaveNo

Open in new window


The second version holds up without changing if you later change the name of the form. It's frustrating that Access didn't throw an error when you had different text in there.

HTH,

pT72
0
 

Author Comment

by:Lambel
ID: 36951879
I tried both. Neither would close the password form.  
0
 
LVL 14

Accepted Solution

by:
pteranodon72 earned 500 total points
ID: 36953196
I've uploaded a copy with the change made. It works for me. The only thing I can think of is that if you made the code change without saving the form, and it closed once with the acSaveNo parameter, the change you just made would be undone. That's a longshot, I admit. Does this upload work properly for you?

pT72
Password-Form.zip
0
 

Author Closing Comment

by:Lambel
ID: 36993783
Sorry for the delay.  Yes, when I downloaded your file and ran it, it worked perfect.  I'll save it away and try to go back and update my tool next time I work on it.  Thanks very much for your help.

Lynn
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question