Never say it's impossible!
Got it figured out.
Here's the VBA module code I used.
All you have to do is pass the MoveWindowToAccessMDIClient your VB.NET
winform's handle. (Setting up the VB.NET application to be COM compatible of
course and using a wrapper class for the form....)
It works, but I haven't tested it extensively so there may be some quirks to
deal with.
'API Declarations
Private Declare Function SetParentAPI Lib "user32" Alias "SetParent" (ByVal
hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function GetWindowAPI Lib "user32" Alias "GetWindow" (ByVal
hWnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetClassNameAPI Lib "user32" Alias "GetClassNameA"
(ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long)
As Long
'API Constants
Private Const GW_CHILD As Long = 5
Private Const GW_HWNDNEXT As Long = 2
Private Const ACCESSMDICLIENTCLASSNAME As String = "MDIClient"
'Private Methods
Private Function pGetClassName(ByVal hWnd As Long) As String
'Returns the window class name.
On Error Resume Next
Dim sClassName As String
Dim lRet As Long
'Get the class name.
sClassName = Space$(255)
lRet = GetClassNameAPI(hWnd, sClassName, 255)
sClassName = Left(sClassName, lRet)
'Return the value.
pGetClassName = sClassName
End Function
Private Function pGetAccessMDIClientHwnd() As Long
'Returns MS Access's MDI Client window handle.
On Error Resume Next
Dim hWnd As Long
'Get the Access Application Handle
hWnd = GetWindowAPI(Access.hWndAccessApp, GW_CHILD)
Do
'If the window class name is "MDIClient" or the handle is 0, then
exit.
If (hWnd = 0) Or (pGetClassName(hWnd) = ACCESSMDICLIENTCLASSNAME)
Then Exit Do
'Get the next window.
hWnd = GetWindowAPI(hWnd, GW_HWNDNEXT)
Loop
'Return the value.
pGetAccessMDIClientHwnd = hWnd
End Function
'Public Methods
Public Function MoveWindowToAccessMDIClient(ByVal hWndChild As Long) As Long
'Moves the specified window to MS Access's MDI Client area.
On Error Resume Next
MoveWindowToAccessMDIClient = SetParentAPI(hWndChild,
pGetAccessMDIClientHwnd)
End Function