Code Insertion (Help)

A

arthursdomain

Im trying to manipulate the access window so that it hides and only the
form is on the screen on startup. Here is the code that I have been
told will be able to do that. However, I dont know where to put it, or
how to set the event to run it. Here are a few of my questions:

1. Where do I put the code
2. Do i use the ON OPEN Event?
3. Do i use the [event procedure] or do i need to put something else
there.

---- copied from http://www.mvps.org/access/api/api0019.htm ----
This same function can also be used to completely hide Access window
and just show your form on the desktop. Make the form popup and from
it's Open Event, call the fSetAccessWindow function with SW_HIDE as the
argument.

Warning: If you're hiding the main Access window, make sure your
error handlers are good. Because with the window hidden, if an error
is raised, pressing "End" on the Error window will NOT make Access
window visible and you will be left with just the form open. A
recommended method is to make a call to fSetAccessWindow with
SW_SHOWNORMAL from your error handlers.
If, for some reason, the Access window does not show itself, then
you can always close the mdb from the Task List, available in Win 95
with Control-Alt-Delete (once) and under NT, by right clicking on the
Taskbar and selecting Task Manager, by selecting the mdb and clicking
End Task.

'************ Code Start **********
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Global Const SW_HIDE = 0
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2
Global Const SW_SHOWMAXIMIZED = 3


Private Declare Function apiShowWindow Lib "user32" _
Alias "ShowWindow" (ByVal hwnd As Long, _
ByVal nCmdShow As Long) As Long

Function fSetAccessWindow(nCmdShow As Long)
'Usage Examples
'Maximize window:
' ?fSetAccessWindow(SW_SHOWMAXIMIZED)
'Minimize window:
' ?fSetAccessWindow(SW_SHOWMINIMIZED)
'Hide window:
' ?fSetAccessWindow(SW_HIDE)
'Normal window:
' ?fSetAccessWindow(SW_SHOWNORMAL)
'
Dim loX As Long
Dim loForm As Form
On Error Resume Next
Set loForm = Screen.ActiveForm
If Err <> 0 Then 'no Activeform
If nCmdShow = SW_HIDE Then
MsgBox "Cannot hide Access unless " _
& "a form is on screen"
Else
loX = apiShowWindow(hWndAccessApp, nCmdShow)
Err.Clear
End If
Else
If nCmdShow = SW_SHOWMINIMIZED And loForm.Modal = True Then
MsgBox "Cannot minimize Access with " _
& (loForm.Caption + " ") _
& "form on screen"
ElseIf nCmdShow = SW_HIDE And loForm.PopUp <> True Then
MsgBox "Cannot hide Access with " _
& (loForm.Caption + " ") _
& "form on screen"
Else
loX = apiShowWindow(hWndAccessApp, nCmdShow)
End If
End If
fSetAccessWindow = (loX <> 0)
End Function

'************ Code End **********


Z
 
D

Dirk Goldgar

Im trying to manipulate the access window so that it hides and only
the form is on the screen on startup. Here is the code that I have
been told will be able to do that. However, I dont know where to put
it, or how to set the event to run it. Here are a few of my questions:

1. Where do I put the code

Paste the code into a new standard module -- that is, one that will be
shown on the Modules tab of the database window. When you save it,
don't give the same name as the function it contains. You can call it
"Module1" if you like, or "modAccessWindow" if you want a more
meaningful name, or some other name that seems good to you.
2. Do i use the ON OPEN Event?

You use an event procedure for the Open event of your startup form to
call the function.
3. Do i use the [event procedure] or do i need to put something else
there.

The On Open event property should be set to "[Event Procedure]". Then
click the "build" button (captioned "...") at the end of the property
line, and create an event procedure that looks like this:

'----- start of code -----
Private Sub Form_Open(Cancel As Integer)
Me.Visible = True
DoEvents
fSetAccessWindow SW_HIDE
End Sub
'----- end of code -----

Note that your form must have both its PopUp ad Modal properties set to
Yes.
 
A

arthursdomain

I did what you instructed, and once i set it to popup yes, it would
open the database then instantly minimize the entire access with form
and it cannot be seen, it is runing in the task manager, but its not on
the task bar nor can i alt+tab to it. Is there anyway to undo the
changes?

Z
 
D

Dirk Goldgar

I did what you instructed, and once i set it to popup yes, it would
open the database then instantly minimize the entire access with form
and it cannot be seen

Did you also set the form's Modal property to Yes, as I instructed?
, it is runing in the task manager, but its not
on the task bar nor can i alt+tab to it. Is there anyway to undo the
changes?

You can kill it from the Task Manager, as the web page explained in its
cautionary note. After you've done that, to get back into the database
without having the form automatically loaded, hold down the Shift key as
you open the database.
 
A

arthursdomain

I did not put modal to yes, however the shift key worked, thank you,
that helped me reopen the database and then i set modal to yes and now
it works perfectly. Many thanks!

Z
 
D

Dirk Goldgar

I did not put modal to yes, however the shift key worked, thank you,
that helped me reopen the database and then i set modal to yes and now
it works perfectly. Many thanks!

You're welcome. It just occurred to me to offer one further caution --
be sure you have a mechanism in place to close the database and quit
Access. For example, executing the statement

DoCmd.Quit

in the Close event of the form that is displayed. You don't want the
user to be able to close the form and leave Access running with no trace
of it on the screen.
 
A

arthursdomain

yep, Had an exit button on the main form, and every form that comes
from the main switch board. I had another problem. I have a switch
board which opens other forms, which work fine after i set popup and
modal to 'yes' however, when i tried the same with reports, they would
not pop up when i clicked on the 'view report' , which would normally
open a window with a report of each form on the switch board. Any
ideas why this would happen?

Z
 
D

Dirk Goldgar

yep, Had an exit button on the main form, and every form that comes
from the main switch board. I had another problem. I have a switch
board which opens other forms, which work fine after i set popup and
modal to 'yes' however, when i tried the same with reports, they would
not pop up when i clicked on the 'view report' , which would normally
open a window with a report of each form on the switch board. Any
ideas why this would happen?

That's the problem with hiding the Access window like that. Only
windows that are not "children" of the Access application window can be
seen, and unlike forms, report print-preview windows don't have PopUp
and Modal properties to make them children of the desktop instead.

I don't know a good way around this, short of either (a) temporarily
showing the Access window again and hiding the form while the report is
open, or (b) doing some sort of wizardry with the Windows API to change
the parent of the report window. That last is not something I've ever
actually tried to do, so I don't know if it's even possible. I have a
vague feeling that I read something about it once, though.
 
A

arthursdomain

Is there a way to make another form which could have a preview of the
report in it? or can I only view a table?

or
"(a) temporarily showing the Access window again and hiding the form
while the report is open"

how would i go about doing A?

Z
 
D

Dirk Goldgar

Is there a way to make another form which could have a preview of the
report in it? or can I only view a table?

I haven't tried this before, but here's an idea. You could export the
report to snapshot format, and then use a form with the Snapshot Viewer
Control on it to display that snapshot. Or you could export the form to
snapshot and start up the snapshot viewer application to display it.
or
"(a) temporarily showing the Access window again and hiding the form
while the report is open"

how would i go about doing A?

I imagine you could use the code at

http://www.mvps.org/access/reports/rpt0003.htm
Reports: Handle reports from a modal form

but add a line to show the Access window again immediately before
opening the report, and then hide it again after the report has been
closed and at least one form has been displayed again. But again, I
haven't tried it.
 

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