Full Version: Relative position of a form
UtterAccess Forums > Microsoft® Access > Access Forms
champagne_charly
Hello there. Have been googling all day trying to find a way to position a form relative to the one behind it. i.e FormA FormB...
Ctrlbutton clicked on form a which opens form b which is then positioned relative to form a.
Can anybody help?
Thanks
Antoine
Jack Cowley
Use the MoveSize method to set both forms then they will always be where you want them to be. See Access help for the details on MoveSize...
th,
Jack
Larry Larsen
Hi
Check out the MoveSize() function.
g:
MoveSize Method Example
The following example moves the active window and changes its height, but leaves its width unchanged:
DoCmd.MoveSize 1440, 2400, , 2000
HTh's
thumbup.gif
champagne_charly
Thanks, now how can I get the position of formA? So that I can move form b to its centre point?
bjective is to create a function for a custom msgbox whereby the msgbox (formb) always opens centered to forma whatever the position and or size may be.
Also what might be useful is knowing how to recover the form name of the open window from which the function is triggered.
Thanks
champagne_charly
*COPY*
Thanks, now how can I get the position of formA? So that I can move form b to its centre point?
bjective is to create a function for a custom msgbox whereby the msgbox (formb) always opens centered to forma whatever the position and or size may be.
Also what might be useful is knowing how to recover the form name of the open window from which the function is triggered.
Thanks
(Sorry in last post didnt check "noitfy reply by email")
Larry Larsen
Hi
THere is another link that will show you a host of form manipulations.
Window Manipulation Examples.<
And for your second question:
Determine name of parent form.
HTH's
thumbup.gif
champagne_charly
You star!! Looks absolutly wicked...Will check it out now. Thanks V Much...
yayhandclap.gif yayhandclap.gif yayhandclap.gif yayhandclap.gif
Larry Larsen
Hi
You're welcome..
thumbup.gif
champagne_charly
Fot the position,I thougght it was going to work a treat unfortunately as I am calling it from a function its giving me nothing but probs confused.gif cryhard.gif crazy.gif
My Main problem is that i can not use the me. in functions how else can I relate to the current form properties (.hwnd , .openargs etc etc) without naming it directly as forms!formA .
Thanks
Antoine
cheekybuddha
Hi Antoine,
You can pass either the form name or even the form itself to your function.
If you post your code I will try and guide you. (But I am going to bed soon!)
d
champagne_charly
Sorry had gone to bed myself. prob is that I DONT want to use the form name as it might be one of many forms. In Fact it can be any form that triggers a MSgbox..As a safety measure and to check everything else works I have temporeraly put in the form name and it works. Problem is doing this without the Forms!FrmMainMenu in function.

I have also attached the file for perusal.
CODE

ption Compare Database
[color="green"]  '************************MsgBox Responce variables [/color]
Public apcmsgval As String
'************************Form Name (attempt)
Private apcformname As String   [color="orange"] '*********************Possible Problem [/color]
Private formNameLONG As String [color="Orange"] '*********************Possible Problem [/color]
[color="green"]'************************Position Variables [/color]
Private Frm1W As String
Private Frm1H As String
Private Frm1T As String
Private Frm1L As String
Private Frm2W As String
Private Frm2H As String
Private Frm2T As String
Private Frm2L As String
Public Function apcmsgbox(FormName As String, _
Optional CaptinText As String, _
Optional buttons As VbMsgBoxStyle, _
Optional Line1 As String, _
Optional Line1FontBold As Boolean) As VbMsgBoxResult
    [color="green"] '*******************Referneces to Forms****************** [/color]

apcformname = FormName    [color="orange"]        '*********************Possible Problem [/color]
formNameLONG = "Forms!" & FormName     [color="orange"]     '*********************Possible Problem [/color]

[color="green"] '*********************** Position and Size of Form A *********************************** [/color]
    
    Dim wp As WM_WINDOWPLACEMENT
On Error Resume Next
If WM_apiIsZoomed(Forms!FrmMainMenu.hwnd) Then             [color="red"] '**** Problem Lies Here********************************** [/color]
    MsgBox "The form window is maximized."
Else
    wp.Length = Len(wp)
    If WM_apiGetWindowPlacement(Forms!FrmMainMenu.hwnd, wp) Then  [color="red"]'**** Problem Lies Here********************************** [/color]
    Frm1L = wp.rcNormalPosition.Left
    Frm1T = wp.rcNormalPosition.Top
    Frm1W = (wp.rcNormalPosition.Right - wp.rcNormalPosition.Left)
    Frm1H = (wp.rcNormalPosition.Bottom - wp.rcNormalPosition.Top)
    End If
End If
    

[color="green"]'************************Open Form B (MSgBox) ********************************** [/color]
DoCmd.OpenForm "frmMsgBox", acNormal, , , acFormReadOnly, acWindowNormal
[color="green"]'************************Set Style of Form B (MSgBox) ********************************** [/color]
Forms!FrmMsgbox.Caption = CaptionTxt
Forms!FrmMsgbox.Label1.Caption = Line1
Forms!FrmMsgbox.Label1.FontBold = Line1FontBold
[color="green"]'*********************** Position and Size of Form B *********************************** [/color]

    
On Error Resume Next
If WM_apiIsZoomed(Forms!FrmMsgbox.hwnd) Then
    MsgBox "The form window is maximized."
Else
    wp.Length = Len(wp)
    If WM_apiGetWindowPlacement(Forms!FrmMsgbox.hwnd, wp) Then
    Frm2L = wp.rcNormalPosition.Left
    Frm2T = wp.rcNormalPosition.Top
    Frm2W = (wp.rcNormalPosition.Right - wp.rcNormalPosition.Left)
    Frm2H = (wp.rcNormalPosition.Bottom - wp.rcNormalPosition.Top)
    End If
End If
    
  [color="green"]   '************* Show Values, Not Necessery but just to verify its working [/color]
    
    Forms!FrmMsgbox!LFrm1L.Caption = Frm1L
    Forms!FrmMsgbox!LFrm1T.Caption = Frm1T
    Forms!FrmMsgbox!LFrm1W.Caption = Frm1W
    Forms!FrmMsgbox!LFrm1H.Caption = Frm1H
    
    Forms!FrmMsgbox!LFrm2L.Caption = Frm2L
    Forms!FrmMsgbox!LFrm2T.Caption = Frm2T
    Forms!FrmMsgbox!LFrm2W.Caption = Frm2W
    Forms!FrmMsgbox!LFrm2H.Caption = Frm2H
End Function
[color="green"]    '************* Testing For Return Values [/color]
Public Function APCMsgResp()
Forms!FrmMainMenu.Text63 = apcmsgval
End Function


'Thanks,

' Antoine







Edited by: champagne_charly on Sat Jan 14 8:07:52 EST 2006.
Edited by: champagne_charly on Sat Jan 14 8:21:11 EST 2006.
champagne_charly
Anybody help? Please
cheekybuddha
Hi there, just got back in!
Is well as referring to your form like this:
Forms!FrmMainMenu
you can also refer to it like this:
Forms("FrmMainMenu")
So, you don't really need the variables apcformname and formNameLONG.
Wherever you have 'Forms("FrmMainMenu")', replace it with:
Forms(FormName)
However, you may run into problems if you are calling your function from a subform. The alternative to get round this would be to pass the form itself rather than its name.
Something like this:
CODE
Public Function apcmsgbox(frm As Form, _
                          Optional CaptinText As String, _
                          Optional buttons As VbMsgBoxStyle, _
                          Optional Line1 As String, _
                          Optional Line1FontBold As Boolean) As VbMsgBoxResult
Dim wp As WM_WINDOWPLACEMENT
On Error Resume Next
    If WM_apiIsZoomed(frm.hwnd) Then      ' <--- See here
        MsgBox "The form window is maximized."
    Else
        wp.Length = Len(wp)
        If WM_apiGetWindowPlacement(frm.hwnd, wp)  ' <--- See here
            Frm1L = wp.rcNormalPosition.Left
            Frm1T = wp.rcNormalPosition.Top
            Frm1W = (wp.rcNormalPosition.Right - wp.rcNormalPosition.Left)
            Frm1H = (wp.rcNormalPosition.Bottom - wp.rcNormalPosition.Top)
        End If
    End If
    ' etc......

This will handle instances if the function is called from a a sub-form, sub-sub-form, sub-sub-sub-form etc as the 'frm' object will be the calling form.
Then when you call the function you would do so like this:
CODE
    If apcmsgbox(Me) = vbYes Then
'       ...
    End If
'
'    or
'
    If apcmsgbox(Forms!frmMainMenu) = vbCancel Then
'       ...
    End If

HAs an extra thing, not related to your problem, I advise you add 'Option Explicit' under your 'Option Comapre' declaration. Then, when you go to the Debug Menu and select 'Compile' it will highlight any typing errors in your variable declarations.
If you look closely, you will see that you have 'Optional CaptinText As String' as one of the arguments of your function - I'm guessing you want to have: 'Optional CaptionText As String'.
cheekybuddha
Hi again Antoine, a small typo above
should read:
hth,
d
champagne_charly
yayhandclap.gif notworthy.gif yayhandclap.gif notworthy.gif yayhandclap.gif
thanks.gif
Shame I cant buy you a beer for that in brixton later...
cheekybuddha
Haha, you're only down the road(ish)! So give a shout if you're ever going to be in the area!
I'm glad that's helped - good luck with the rest. thumbup.gif
d
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.