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!

How to maximize Access (as Automation Server) 1

Status
Not open for further replies.

LarryClark

Programmer
Nov 27, 1998
2
0
0
US
I'm trying to launch Access from VB for report printing. This much works OK.<br>
<br>
Set ObjAccess = CreateObject("Access.Application")<br>
With ObjAccess<br>
.Visible = True<br>
.OpenCurrentDatabase (MyPath & MyDbname)<br>
RptName = "Whatever"<br>
.DoCmd.OpenReport RptName, 2<br>
.DoCmd.SelectObject 3, RptName 'acReport=3<br>
.DoCmd.Maximize<br>
End With<br>
<br>
The last set of instructions maximize the report's MDI child within the Access window. However, I have been unable to maximize the Access window itself.<br>
<br>
I have tried using SendKeys, but I cannot get the right window activated:<br>
AppActivate "Microsoft Access"<br>
SendKeys "% X"<br>
(I was running the above before opening a document, and my tests seemed to indicate that the window title contained only "Microsoft Access".)<br>
<br>
I also tried inserting the following:<br>
Declare Function ShowWindow Lib "User32" _<br>
(ByVal hWnd As Long, ByVal nCmdShow As Long)<br>
Global Const SW_MAXIMIZE As Long = 3<br>
hWndAccess = .hWndAccessApp<br>
Temp = ShowWindow(hWndAccess, SW_MAXIMIZE)<br>
When I run this, the ShowWindow produces a "bad DLL calling convention." What am I missing?<br>
<br>
Alternatively, I'll settle for any technique that works!<br>
Thanks for any suggestions.
 
You COULD simply run the SHELL command from VB, starting Access with a suitable macro from the command line. It's cheap, I know, but it works for me...
 
That will indeed launch Access, but I won't get back an object handle so that I can perform other actions on it. Once it's launched, I could find it via GetObject, but I would think there'd be a more direct way via CreateObject.
 
Also could try this. For some reason you have to make Two calls to the window to get it to work.<br>
<br>
Private Declare Function apiSetForegroundWindow Lib _<br>
"user32" Alias "SetForegroundWindow"(ByVal hwnd As Long) _<br>
As Long<br>
<br>
Private Declare Function apiShowWindow Lib "user32" Alias _ "ShowWindow"(ByVal hwnd As Long, ByVal nCmdShow As Long) _<br>
As Long<br>
<br>
Private Const SW_MAXIMIZE = 3<br>
<br>
Set objAccess = New Access.Application<br>
With objAccess<br>
lngRet = apiSetForegroundWindow(.hWndAccessApp)<br>
lngRet = apiShowWindow(.hWndAccessApp, SW_MAXIMIZE)<br>
'the first call to ShowWindow doesn't seem to do anything<br>
lngRet = apiShowWindow(.hWndAccessApp, SW_MAXIMIZE)<br>
.OpenCurrentDatabase (MyPath & MyDbname)<br>
RptName = "Whatever"<br>
.DoCmd.OpenReport RptName, 2<br>
.DoCmd.SelectObject 3, RptName 'acReport=3<br>
.DoCmd.Maximize<br>
End With<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top