Improve company productivity with a Business Account.Sign Up

x
?
Solved

MSAccess Password Form - Auto close when entered

Posted on 2011-09-29
15
Medium Priority
?
352 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
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

608 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