Access 2K: Easily answerable questions about UserForms, etc.

M

Mike Mertes

Greetings again, all.

Please excuse me for asking questions that have doubtless been asked and
answered here thousands of times previous! If I weren't in a jam for time
I'd do my own research :) Anyway, two quick and easy questions follow:

1. What is the preferred method for hiding a UserForm programmatically?

I tried "Me.Visible = False," which does work, but after the Form_Open event
is finished executing my user form reappears! :( Maybe the solution is
unrelated?

2. Is there any way to Compact and Repair programmatically?

When I call "RunCommand acCmdCompactDatabase" from a Form_Close event the
compiler gives me an error explaining that, "You can't compact the open
database while running a macro or Visual Basic code."

That's it.
TIA!
 
D

Dirk Goldgar

Mike Mertes said:
Greetings again, all.

Please excuse me for asking questions that have doubtless been asked
and answered here thousands of times previous! If I weren't in a jam
for time I'd do my own research :) Anyway, two quick and easy
questions follow:

1. What is the preferred method for hiding a UserForm
programmatically?

First be aware that Access forms aren't UserForms. If you use that
term, it may confuse people reading your messages. That is, of course,
unless you really are referring to an Office UserForm, and not an Access
Form object at all.
I tried "Me.Visible = False," which does work, but after the
Form_Open event is finished executing my user form reappears! :(
Maybe the solution is unrelated?

Me.Visible = False is in fact the preferred solution, but it doesn't
work when the form is first opening.

If you know at open time that you want to hide the form, just say that
when you open it:

DoCmd.OpenForm "Form1", WindowMode:=acHidden

Most of the time you can hide a form by saying (form reference).Visible
= False, but the sequence of events that takes place when the form is
opening makes this tricky. If you really need to hide a form in its
Open event, one thing you can do is resize the form to height and width
of 0, 0, and then use a Timer event -- set to fire a millisecond
later -- to make it invisible, then restore its original dimensions. I
was trying to do this, just as a challenge, so I know that it works, but
I haven't found any practical reason to use it.
2. Is there any way to Compact and Repair programmatically?

When I call "RunCommand acCmdCompactDatabase" from a Form_Close event
the compiler gives me an error explaining that, "You can't compact
the open database while running a macro or Visual Basic code."

See this link:

http://www.mvps.org/access/general/gen0013.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top