Dirk said:
In the above case, I opened the form to the left of the calling control, but
it should be straightforward to modify the code to get other relative
positions.
Good example Dirk.
This is much simpler than using APIs like I've found in most other examples.
Thanks
I need this to open a popup form to the right of the command button so I
created this variation.
works by calling it as a sub procedure with parameters
and uses more variables for position to get the relative position to the
right of the control
'------ start of code ------
' sCForm is the Calling Form Name
' sCCtrl is the Calling Control Name
' strFormToOpen is the Name of the Form to Open
'
Sub SetFormPosition(sCForm As String, sCCtrl As String, strFormToOpen As
String)
Dim ctlTarget As Access.Control
Dim lngBorderHoriz As Long
Dim lngBorderVert As Long
Dim lngCmdWidth As Long
Dim lngCmdHt As Long
Dim lngCmdTop As Long
Dim lngFrmHt As Long
Dim lngLeftBuffer As Long
Set ctlTarget = Forms(sCForm).Controls(sCCtrl)
DoCmd.OpenForm strFormToOpen
With Forms(sCForm)
lngBorderHoriz = (.WindowWidth - .InsideWidth) / 5 ' adjust value for
position as needed
lngBorderVert = (.WindowHeight - .InsideHeight) / 2
lngCmdWidth = ctlTarget.Left + ctlTarget.Width
lngCmdHt = ctlTarget.Height
lngCmdTop = ctlTarget.Top
lngFrmHt = Forms(strFormToOpen).WindowHeight
' Buffer value for space from right of control to left of popup form
lngLeftBuffer = 100
nWinLeftPos = .WindowLeft + lngBorderHoriz + lngCmdWidth + lngLeftBuffer
nWinTopPos = .WindowTop + lngBorderVert + lngCmdTop + lngCmdHt - lngFrmHt
End With
' Moves the form position
Forms(strFormToOpen).Move nWinLeftPos, nWinTopPos
End Sub
'------ end of code ------