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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to Hide Database Window With VBA Code 1

Status
Not open for further replies.

caibo

Programmer
Jul 13, 2000
9
0
0
CA
My application hides the Database Window at startup. A subsequent call to select a report object in VBA code causes the Database Window to become visible. How can I hide the Database Window using VBA code?

Peter Caine
caibo@wwdb.org
 
The following will do it:
Code:
    DoCmd.SelectObject acReport, , True
    DoCmd.RunCommand acCmdWindowHide
Caution: If you're single-stepping, this may close the module window instead. Rick Sprague
 
Thanks Rick;

I was invoking the report from a control button on a form. I reopened my main form then my report selection form after issuing the hide window command and everything works perfectly.

Peter Caine
caibo@wwdb.org
 
I am using Access 97; it's the only version I address in this post. Now, though this thread is over a year old ... for the benefit of future readers like myself ...


This was exactly the question I was looking to answer when I came here today :) ! And RickSpr's reply is correct. I copied it and moved on to look for more. I just found another post, under another person's question, which immediately struck me as just what I was looking for. And it is pretty much the same answer, as it turns out :} . It's just a bit better commented and provides both hide and unhide code (Specifically labeled). So it just helped me figure out why the code worked without researching it much further. I'll add more illuminating commentary after copying the other helpful post here:

****START Copy of another member's (rhicks) post****
rhicks (Programmer) Apr 27, 2000
[...]
Code:
'To show the Database Window
DoCmd.SelectObject acTable, , True

'To Hide the Database Window
DoCmd.SelectObject acTable, , True
DoCmd.RunCommand acCmdWindowHide
HTH
RDH

Ricky Hicks
rdhicks@mindspring.com
****END Copy of another member's (rhicks) post****

The Reason These Code Snippets Work:
-------------------------------------
See Help for the DoCmd.SelectObject method. After reading that, I realised the following.

A) Any time you use the DoCmd.SelectObject method with True as the third argument, the Database Window is displayed; if it was hidden, it will be unhidden and remain that way. (From this programmer's stand-point, this is a side-effect, but the choice could be argued either way with some grounds.)

B) If you do not give a second argument to the DoCmd.SelectObject method (in which case the third argument is *required* to be True), the Database Window is opened without opening any other objects. The first argument then also specifies which tab of the Database Window should be displayed when this happens. (If you don't care which tab is on top, just wanting the Database Window to open, then RickSpr's and rhicks's code lines are equivalent; one shows the Reports Tab, and one shows the Tables Tab, but the point is that neither actually opened any other objects, leaving the Database Window as the active window.)

C) The Database Window has no associated object or properties, so you can't reference it explicitly.
C1) If you want to just *show* the Database Window without opening another object, use the code above, and the Database Window will open -- becoming the active *window*. (If you want to make the Database Window visible, but leave another object with the active focus, you'll have show the Database Window, then change the focus with more code.)
C2) And if you want to *hide* the Database Window, you have to *show* it -- which makes it the active window -- **then** hide it -- by hiding the active window.

It's too bad there's no clear way to explicitly reference the Database Window itself, but the 1-line and 2-line code snippets above work just fine.

And now my
Sub PrintForm(strFormName as String)
routine works just fine without permanently displaying the Database Window when I print an unopened form!

Thinking aloud: I don't know how bad the momentary display of the Database Window *could* be if I had a *malicious* user trying to stop things with the Database Window displayed; but I think that most of them here are indifferent enough that it won't cause a worry. Perhaps, since printing opens a closed form (or report) anyway, albeit temporarily, perhaps I should just use DoCmd.OpenForm (or DoCmd.OpenReport), then print, then DoCmd.Close the form (or report) -- instead of using DoCmd.SelectObject at all for unopened form (or report). If the form (or report) were already open, I wouldn't want to use the DoCmd.OpenForm (or DoCmd.OpenReport) method, because I might lose Ordering of Filtering; but in that case, DoCmd.SelectObject with False as the third argument is just fine, and never opens the Database Window :))) .
... WAIT! If I don't want them to see the Database Window or form coming up, I can use DoCmd.Echo False before printing, then DoCmd.Echo True after printing. (DoCmd.Echo turns screen updating on or off based on the argument provided.) Yeah ... that's the ticket!

Thanks to RickSpr and rhicks! I appreciate your answers!



-- C Vigil =)
(Before becoming a member, I also signed on several posts as
"JustPassingThru" and "QuickieBoy" -- as in "Giving Quick Answers")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top