DataBase - Position form near control that called it
Asked By Barry
19-Jan-10 11:24 PM
Howdy:
I would like to position a form (a calendar) near the control that issued a
call to open the calendar form. So, wherever on my calling form there is a
control that requires a date, the calendar form will open just beneath that
control. Is this a job for MoveSize? Any examples around to show the way?
I look forward to your input.
Thanks,
Barry
DoCmd.OpenForm
(1)
Access.Control
(1)
StrFormToOpen
(1)
DropDownForm
(1)
SomeFormName
(1)
NWinLeftPos
(1)
NWinTopPos
(1)
APIs
(1)
Stuart McCall replied to Barry
There is more to this than you might imagine. Here is what I use:
http://www.smccall.demon.co.uk/Forms.htm#OpenUnder
HTH
Barry replied to Stuart McCall
Stuart:
Thanks. that certainly is more than I had bargained for. I was hoping that
there was a method I might actually understand. This will give me something
to chew on for a while. Is there no other way to find the position of a
control using the Access form's Left, Top and Down in relation to the Access
window?
Thanks again,
Barry
Dirk Goldgar replied to Barry
Some time ago, I worked this out for a newsgroup post:
'------ start of code ------
Dim strFormToOpen As String
Dim ctlTarget As Access.Control
Dim lngBorderHoriz As Long
Dim lngBorderVert As Long
strFormToOpen = "SomeFormName"
Set ctlTarget = Me.ActiveControl
DoCmd.OpenForm strFormToOpen
lngBorderHoriz = (Me.WindowWidth - Me.InsideWidth) / 2
lngBorderVert = (Me.WindowHeight - Me.InsideHeight) / 2
With Forms(strFormToOpen)
.Move _
(Me.WindowLeft - .WindowWidth) + lngBorderHoriz +
ctlTarget.Left, _
Me.WindowTop + lngBorderVert + ctlTarget.Top
End With
'------ end of code ------
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.
--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html
(please reply to the newsgroup)
Stuart McCall replied to Barry
The way Access forms are constructed and their built-in behaviour makes this
more of a task than we'd like. Fortunately you do not need to understand the
code in order to use it. Just follow the easy instructions in the
DropDownForm procedure.
Barry replied to Dirk Goldgar
Dirk:
Thanks so much for your help. At least this is something that I can wrap my
head around. I will give it a try in my app as soon as I have a moment.
Thanks again.
Barry
Linq Adams via AccessMonster.com replied to Barry
I have not used it in awhile, but I believe Allen Brown's form based calendar
does exactly that:
http://allenbrowne.com/ser-51.html
--
Message posted via http://www.accessmonster.com
Bill replied to Dirk Goldgar

Good example Dirk.
This is much simpler than using APIs like I have 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 ------
Stuart McCall replied to Bill
That code will work for a form set up in a particular way, not the general
case though. If that is sufficient for your needs then fair enough. However:
Try switching on the main form's header. Try it with and without a record
selector on the main form. Try it with the control to be opened under close
to the right or bottom of the screen. Also try with the main form control on
a tab page. Those are just the things that spring to mind - I wrote my
module quite some time ago so I am a bit vague on all the pros and cons, but
you will meet them, guaranteed.
On Error GoTo ErrorHandler Select Case Me.lstQuickSearch.Value Case 1: If IsNull(txtSearchBox) Then DoCmd.OpenForm ("[frmListforCompanyID") DoCmd.GoToControl ("cboSearchBox") Else DoCmd.OpenForm ("frmListforCompanyID") DoCmd.GoToControl ("cboSearchBox") Forms!frmListforCompanyID!cboSearchBox.ControlSource = txtSearchBox End If Case 2: If IsNull(txtSearchBox) Then DoCmd.OpenForm ("frmListforCompanyName") DoCmd.GoToControl ("cboSearchBox") Else DoCmd.OpenForm ("frmListforCompanyName") DoCmd.GoToControl ("cboSearchBox") Forms!frmListforCompanyName!cboSearchBox.ControlSource = txtSearchBox End If Case 2: If IsNull
tried so many things in the past few months. Please help. Access Forms Coding Discussions DoCmd.OpenForm (1) FormApplicationPg02InetLiaison (1) FormApplicationPg02SalesRep (1) FormApplicationPg02CstmrSvc (1) FormApplicationPg02AdmnAsst (1) VBA (1) FormApplicationPg02Cstdn (1) SmplApplNmFirst (1 As String If Me![emplt_pstn_] = 1 Then stDocName = "f_02_custodian" 'stLinkCriteria = "[applcnID] = " & Me![applcnID] DoCmd.close DoCmd.OpenForm stDocName, , , stLinkCriteria Else If Me![emplt_pstn_] = 2 Then stDocName = "f_02_admin_clerk" 'stLinkCriteria = "[applcnID] = " & Me![applcnID] DoCmd.close DoCmd.OpenForm stDocName, , , stLinkCriteria Else If Me![emplt_pstn_] = 3 Then stDocName = "f_02_secretary" 'stLinkCriteria = "[applcnID] = " & Me![applcnID] DoCmd close DoCmd.OpenForm stDocName, , , stLinkCriteria Else If Me![emplt_pstn_] = 4 Then stDocName = "f_02_eqp_rpr" 'stLinkCriteria = "[applcnID] = " & Me![applcnID] DoCmd
is a popup form instead of the standard boring gray rectangle? Access Forms Coding Discussions DoCmd.OpenForm (1) DoCmd.Close (1) Forms.messageform.messagetextbox (1) VBA (1) StLinkCriteria (1) PaycheckID (1) LblErrDesc to be closed to continue) then in your code where you had a message box DoCmd.OpenForm "messageform" Forms.messageform.messagetextbox = "here is your text" hope this helps Barry Barry's idea this suspends further code from running in the module that called it. Ex: somecode somecode DoCmd.OpenForm "FormName", , , , , acDialog thiscode willnotrun untiltheform isclosed If you like, rather than referring to the message as an open arg and handle it in the open even of the popup form. . . DoCmd.OpenForm "FormName", , , , , acDialog, "This Message" Then, in the open event, you read the open args and
another Form to the Form "Opening" w / code in the "Parts" Form. . . Private Sub Form_Close() DoCmd.OpenForm "Opening", acNormal, , , , acWindowNormal End Sub Even Form_Load in the "opening" Form includes Field1.SetFocus. The Dimmed until a Mouse Click. Ideas? TIA - Bob Access Modules DAO Discussions ForSafe.SetFocus (1) DoCmd.OpenForm (1) Screen.MousePointer (1) Opening.SetFocus (1) Field1.SetFocus (1) List2.SetFocus (1) DoCmd.Maximize it w / Form_Activate, Form_Load & Form_Open. It is an Unbound Form. Interesting. . .from the "Parts" Form. . . DoCmd.OpenForm "Opening", , , , , acDialog - -> WILL SetFocus. However, navigating back-&-forth (w / the acDialog) between the 2 Forms 11 / 10 - 2004 Archive Allen Browne - DoCmd.Close acForm, Me.Name (seems to run faster) DoCmd.OpenForm "Parts": DoCmd.Close acForm, Me.Name 'DoCmd.Close acForm, Case 2 'Machine-based Entry Screen
another record. What is the best way to pull this off? Access Forms Coding Discussions DoCmd.OpenForm (1) VBA (1) LeafletID (1) Database (1) IDField (1) StLinkCriteria (1) LeafletDetail (1) FindFirst (1 As String Dim stLinkCriteria As String stDocName = 3D "LeafletDetail" stLinkCriteria = 3D "[LeafletID] = 3D" & Me![LeafletID] DoCmd.OpenForm stDocName, , , stLinkCriteria Exit_Command129_Click: Exit Sub Err_Command129_Click: MsgBox Err.Description Resume Exit_Command129_Click End Sub and this s take a closer look at the line you are using to open the form. . . DoCmd.OpenForm stDocName, , , stLinkCriteria if you type DoCmd.OpenForm into the VBA editor, followed by a space, you will see a list of arguments