Minimize current database & Open a different database (1 Viewer)

mark curtis

Registered User.
Local time
Today, 19:43
Joined
Oct 9, 2000
Messages
457
Dear all,

Please can anyone supply me with the code that when I click a command button on the current database it will minimize and open a different access database, which will maximize and be the focus in the window?

I am struggling.

Thanks
Mark
 

jonnie_c

Registered User.
Local time
Today, 19:43
Joined
May 11, 2002
Messages
25
There are a lot of ways to go about that, but here is the one i consider to be the simplest:

Sub Command_Click()
fSetAccessWindow(
strPathtoDBase = "X:\PATHTODBASE\db.mdb"
strString = "X:\Program Files\Microsoft Office\Office\MSACCESS.EXE " & Chr(34) & strPathtoDBase & Chr(34)
Call Shell(strString, vbMaximizedFocus)

End Sub

'************ Code Start **********
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 **********
This function is from mvps: http://www.mvps.org/access/api/api0019.htm
 

jonnie_c

Registered User.
Local time
Today, 19:43
Joined
May 11, 2002
Messages
25
oops. forgot to format. sorry.
 

Users who are viewing this thread

Top Bottom