Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with closing a popup form in Access (by VBA code)

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hello everybody,

Could anyone help me with my problem?
How do I close a popup form (the form's modality and popup property is set to "yes")?
I tried using:
DoCmd.Close acForm, "NameOfForm"

Or even tried unloading it first:

Unload NameOfForm

But neither of them worked. = (

I suppose, I just need the DoCmd.Close method to close a form, don't I?
I tried closing another form in my database using this DoCmd.Close acForm and it worked. So I don't think it's because of the database file.
But how come the DoCmd.Close doesn't work with this popup Form?
Does anyone know how I can close the popup form?

Thank you for your time and help in advanced!
Oh...
I'm very new to this site by the way...
= }

Thank you,
-nano-
 
Hi!

Where is your close command? It needs to be run in the code of the modal form for it work because any code that was running before the form popped-up will be suspended until the modal form closes.

hth
Jeff Bridgham
bridgham@purdue.edu
 
Thanks for your reply Jeff !!!


Well, by the way.
Let me put this clearer.

I have 2 forms in my Access database. Their names are: "Main" and "Password". On the "Main" form, I put a command button that will call this second form, "Password", as a popup form.

On this "Password" form, I put a unbound textbox (i.e. "Textbox1"). I set the password to be "3Stooges". And so, in the property of "Textbox1", I set a Validation Rule of "3Stooges". And I tried to close the "Password" form (where this "Textbox1" is in) by writing an Event Procedure in the Textbox1's "On Exit" property. My idea was to write a Private Sub in this Textbox1's "On Exit" property, that would just close the whole "Password" form.
But it wouldn't do it. Give me some object-related error.

I think it's trying to tell me that I can't close the Popup form as it's still running an event procedure that is embedded in it, maybe?

I put Validation Rule, so that if the user entered a invalid password, it would just give the user the "Validation text" message I put in the property, and would just exit the Private Sub. But if user enters a correct password ("3Stooges"), I tried to close both the "Main" and "Password" forms. But it just closes the "Main" form; never closes the "Password" --> Give errors all the time.

Do you know what is happening here?

Again,
thank you very much for your help in advanced!

-nano18- = ]
 
Hi!

It would be useful to see the specific errors you are getting. I am having some trouble understanding what exactly you are doing with these two forms and what the use of the password form is. One thing I can tell you is that I would not use a validation rule in the text box and validation in a procedure, personally I would use the procedure.

Jeff Bridgham
bridgham@purdue.edu
 
Again, thanks for your reply!


My main goal is to prevent regular users from closing the activeForm and see all of the Tables, Queries, and any other "internals" of the database.
I am new to the Access VBA, and so... do you know any simpler way to do it?

I used an InputBox before, where user would be prompted with an InputBox for a password. So, if they know the password, they can close the current active form and change or mess up with the tables, queries and forms in the database. But the thing with InputBox, everybody can see what is typed into the InputBox. I can't make the appearance to be like "*********" (just like when we type password onto FTP site, etc.)

And so I tried creating another form, and made this form a popup form. I was hoping I can make it as a custom InputBox, but then bump into this problem that I can't even close this new "password" form myself. = ( = (

Tried using these below to close it, but nothing was a success:

Unload Me
DoCmd.Close acForm, "Password" ---> "Password" is the name of the form

DoCmd.DeleteObject Me

Sometimes they give me error "429 - ActiveX Component can't create object"
Sometimes "Compile Error - Type mismatch"

What do you think about it?

Again,
thank you much!

-nano18-


 
Hi again!

In your form, instead of opening another form, put a password textbox. Then, in the close event procedure of the form use this code:

If Me!YourPasswordTextBox.Value <> &quot;YourPassword&quot; Then
DoCmd.Quit
End If

Now if anyone closes the form without using the correct password Access will close down too.

hth
Jeff Bridgham
bridgham@purdue.edu
 
Hello Jeff,

Thank you for your reply!!
Yes, my Access is working fine now....

Thank you again,
nano18
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top