Solved

MSAccess Password Form - Auto close when entered

Posted on 2011-09-29
15
296 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
  • 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now