Open form relative to another form

  • Thread starter Thread starter 0 1
  • Start date Start date
0

0 1

I'm trying to use the clFormWindows.Bas class module at
http://www.mvps.org/access/forms/frm0042.htm to open a popup form
(frmPopUp) in a location relative to a subform form (fsubOrders).

1. I inserted the clFormWindows.Bas text as a Class Module and named
it clFormWindow.
2. Compiled.
3. I added the Public Sub code to frmPopUp:

Public Sub AlignTops(ByRef frmA As Form, ByRef frmB As Form)
Dim fwA As New clFormWindow, fwB As New clFormWindow
fwA.hwnd = frmA.hwnd
fwB.hwnd = frmB.hwnd
If fwA.Top < fwB.Top Then
fwB.Top = fwA.Top
Else
fwA.Top = fwB.Top
End If

Set fwA = Nothing
Set fwB = Nothing
End Sub

4. I added this to the OnLoad event of frmPopUp:

Private Sub Form_Load()
Call AlignTops(Forms!frmMain!fsubOrders, Me)
End Sub

When frmPopUp loads, I get a "Run-Time error 13 Type mismatch'. Debug
points to the Call AlignTops line.

What am I missing?
 
0 1 said:
I'm trying to use the clFormWindows.Bas class module at
http://www.mvps.org/access/forms/frm0042.htm to open a popup form
(frmPopUp) in a location relative to a subform form (fsubOrders).

1. I inserted the clFormWindows.Bas text as a Class Module and named
it clFormWindow.
2. Compiled.
3. I added the Public Sub code to frmPopUp:

Public Sub AlignTops(ByRef frmA As Form, ByRef frmB As Form)
Dim fwA As New clFormWindow, fwB As New clFormWindow
fwA.hwnd = frmA.hwnd
fwB.hwnd = frmB.hwnd
If fwA.Top < fwB.Top Then
fwB.Top = fwA.Top
Else
fwA.Top = fwB.Top
End If

Set fwA = Nothing
Set fwB = Nothing
End Sub

4. I added this to the OnLoad event of frmPopUp:

Private Sub Form_Load()
Call AlignTops(Forms!frmMain!fsubOrders, Me)
End Sub

When frmPopUp loads, I get a "Run-Time error 13 Type mismatch'. Debug
points to the Call AlignTops line.

What am I missing?

Forms!frmMain!fsubOrders refers to the subform control on frmMain, which is
not a form object and doesn't have a .hWnd property. Finding it's screen
location is not an easy task.
 
Back
Top