Solved

Opening MS Access 'UnDocked'

Posted on 2007-03-22
11
174 Views
Last Modified: 2012-09-26
Hi,
I have a VB2005 Express Edition program that successfully opens a standalone MS Access 2003 application with full focus when required.  However, it opens what appears to be a 'docked' window.  If I open the MS Access app separately it opens full screen.  
Please can anyone advise the necessary VB coding I need to add to allow me to open the Access app from within my VB program so that it opens full screen?  (As a note, when I close the MS Access App, focus is returned to the VB program, so I'm not concerned with losing sight of the VB program.)

Thank you.
Regards,
Keith
0
Comment
Question by:keithedwardb
  • 5
  • 3
  • 3
11 Comments
 
LVL 39

Expert Comment

by:stevbe
Comment Utility
In the old world using Shell you can define how the new process opens (hidden, min, max, normal), hopefully the methos you are calling now to open the app has the same options. Got code?
0
 

Author Comment

by:keithedwardb
Comment Utility
Hi Stevbe,
No, I don't have any code for this.  It's not an area I've had experience of before.  Can you enlighten me?

Thanks,
Regards,
Keith
0
 
LVL 39

Expert Comment

by:stevbe
Comment Utility
what is the code you are using now to open the Access app from your VB2005 app?
0
 

Author Comment

by:keithedwardb
Comment Utility
Hi,
Sorry, I misunderstood.  Below is the code that opens the database.  (The code conn.CloseCurrentDb runs later, inside a Do While loop) .  Hope this helps.
Regards,
Keith

With conn
            .OpenCurrentDatabase("C:\Documents and Settings\kblakesley\" & _
            "My Documents\DATABASES\Under Development\DVTCamera\SPCProgram\" & _
            "SPCProgram2003.mdb", False)
            .DoCmd.RunMacro("AutoExec.DVT")
            .Visible = True
End With
0
 
LVL 7

Expert Comment

by:JTennessen
Comment Utility
Do you have design access to the Access database? If so, you can do it like this. First, put this code in a module:

    Private Declare Function GetActiveWindow _
      Lib "user32" () As Long
    Private Declare Function GetParent _
      Lib "user32" ( _
      ByVal hwnd As Long) As Long
    Private Declare Function ShowWindow _
      Lib "user32" ( _
      ByVal hwnd As Long, _
      ByVal nCmdShow As Long) As Long
   
    Public Function AccessMaximize() As Long
   
      AccessMaximize = ShowWindow(GetAccesshWnd(), 3)
   
    End Function
   
    Private Function GetAccesshWnd() As Long
   
      Dim hwnd As Long
      Dim hWndAccess As Long
     
      hwnd = GetActiveWindow()
      hWndAccess = hwnd
     
      While hwnd <> 0
        hWndAccess = hwnd
        hwnd = GetParent(hwnd)
      Wend
     
      GetAccesshWnd = hWndAccess
   
    End Function

Then Create a macro, add a RunCode action to it, and in the Function Name argument, type

    AccessMaximize()

Save the macro and name it AutoExec. Now every time this database is opened, regardless of what method was used to open it, it will maximize the main Access window.

HTH,
Jeff
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 39

Expert Comment

by:stevbe
Comment Utility
With conn
            .OpenCurrentDatabase("C:\Documents and Settings\kblakesley\" & _
            "My Documents\DATABASES\Under Development\DVTCamera\SPCProgram\" & _
            "SPCProgram2003.mdb", False)

             'add this ...
            .DoCmd.RunCommand acCmdAppMaximize

            .DoCmd.RunMacro("AutoExec.DVT")
            .Visible = True
End With
0
 

Author Comment

by:keithedwardb
Comment Utility
FAO JTenneson.  Hi, I pasted the code into Access and included the call to AccessMaximize within my AutoExec and it opens maximized, but not when activated from my VB Program.

FAO Stevbe
Hi, I tried your suggestion and found I had to add (Access.AcCommand to the .acCmdAppMaximize) to get it to register without a syntax error.  However, the result was the same as before with Access opening docked.

Thanks to both for trying.  
0
 
LVL 7

Expert Comment

by:JTennessen
Comment Utility
Ah, my apologies. All you need to do is add another .DoCmd.RunMacro statement *after* your .Visible = True statement to run the AccessMaximize portion of your AutoExec. Sorry for the oversight!

Jeff
0
 

Author Comment

by:keithedwardb
Comment Utility
Hi Jeff,
I placed the AccessMaximize within my AutoExec.DVT but the results the same, I'm afraid.  The funny thing is, I created a macro within Word that clicked the expand button and then copied the code into Access.  Suffice to say that Word 2003 VBA and Access 2003 VBA don't seem to be the same and I can't seem to find the equivalent.
Regards,
Keith
0
 
LVL 7

Accepted Solution

by:
JTennessen earned 250 total points
Comment Utility
Right. The trick is that it has to run *after* the window is made visible, so if you move .DoCmd.RunMacro("AutoExec.DVT") down a line, it should work. Let me know if you still have trouble.

Jeff
0
 

Author Comment

by:keithedwardb
Comment Utility
Bingo!  That cracked it.  Why I didn't try that permutation in the interim, I don't know.  Thank you for your help on this, it has me back on track.  Thanks again.

Regards,
Keith
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now