Results 1 to 14 of 14
  1. #1
    Join Date
    Oct 2004
    Location
    Oxfordshire, UK
    Posts
    89

    Question Unanswered: Opening a Form at a Specific Postion

    Hi All,

    I'm opening a pop-up form from a control (ctlLaunch) on another form (frmParent). The idea is to open the popup immediately below ctlLaunch and with the same left position. I can position the popup relative to the control but there's some overlap. Here's the code I'm using:

    'Pop-up Form OnOpen Event:
    Private Sub Form_Open(Cancel As Integer)
    On Error GoTo Err_Form_Open

    MoveForm Screen.ActiveForm, Screen.ActiveControl

    Exit_Form_Open:
    Exit Sub

    Err_Form_Open:
    MsgBox Name & "_Open Error: " & Err.Number & ": " & Err.Description
    Resume Exit_Form_Open
    End Sub

    Public Sub MoveForm(ByVal frmParent As Form, ByVal ctlLaunch As Control)
    On Error GoTo Err_MoveForm
    Dim rctParent As RECT
    Dim lngLeft As Long
    Dim lngTop As Long
    Dim lngWidth As Long
    Dim lngHeight As Long

    'Get parent form RECT.
    GetWindowRect frmParent.hwnd, rctParent
    With rctParent
    lngLeft = .Left
    lngTop = .Top
    lngWidth = .Right - .Left
    lngHeight = .Bottom - .Top
    End With
    'Convert RECT dimensions to twips
    CPixTwip lngLeft, lngTop, lngWidth, lngHeight
    'Get CurrentSection position relative to parent form window.
    With frmParent
    lngLeft = lngLeft + .CurrentSectionLeft
    lngTop = lngTop + .CurrentSectionTop
    End With
    'Get CurrentSection position relative to parent form window.
    With ctlLaunch
    lngLeft = lngLeft + .Left
    lngTop = lngTop + .Top + .Height
    End With
    'Move last form object opened to new position.
    DoCmd.MoveSize lngLeft, lngTop

    Exit_MoveForm:
    Exit Sub

    Err_MoveForm:
    MsgBox "MoveForm Error: " & Err.Number & ": " & Err.Description
    Resume Exit_MoveForm
    End Sub

    Public Sub CPixTwip(lngLeft As Long, lngTop As Long, lngWidth As Long, lngHeight As Long)
    On Error GoTo Err_CPixTwip
    Dim lngHDC As Long
    Dim lngReturn As Long
    Dim lngXPixPerIn As Long
    Dim lngYPixPerIn As Long
    Const LOGPIXELSX = 88
    Const LOGPIXELSY = 90
    Const TWIPSPERINCH = 1440

    'Get pixels per inch.
    lngHDC = GetDC(0) 'desktop display device context.
    lngXPixPerIn = GetDeviceCaps(lngHDC, LOGPIXELSX)
    lngYPixPerIn = GetDeviceCaps(lngHDC, LOGPIXELSY)
    lngReturn = ReleaseDC(0, lngHDC)
    'Return dimensions in twips.
    If lngLeft > 0 Then
    lngLeft = (lngLeft / lngXPixPerIn) * TWIPSPERINCH
    End If
    If lngTop > 0 Then
    lngTop = (lngTop / lngXPixPerIn) * TWIPSPERINCH
    End If
    lngWidth = (lngWidth / lngXPixPerIn) * TWIPSPERINCH
    lngHeight = (lngHeight / lngYPixPerIn) * TWIPSPERINCH

    Exit_CPixTwip:
    Exit Sub

    Err_CPixTwip:
    MsgBox Err.Number & " " & Err.Description
    Resume Exit_CPixTwip
    End Sub

    What am I missing? Is there a better way?

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Hi

    Coo - that seems rather a lot of work for a wee feature like that. Below seems to work ok for me - more convoluted and verbose than necessary but you can tidy it up eh?

    Code:
    'The calling form
    Private Sub Command0_Click()
    On Error GoTo Err_Command0_Click
        Dim intTop As Integer
        Dim intLeft As Integer
     
        intTop = Me.txtBelowMe.Top
        intTop = intTop + Me.txtBelowMe.Height
     
        intLeft = Me.txtBelowMe.Left
        DoCmd.OpenForm "frpPopUpBelowControl", , , , , , intTop & ":" & intLeft
    Exit_Command0_Click:
        Exit Sub
    Err_Command0_Click:
        MsgBox Err.Description
        Resume Exit_Command0_Click
     
    End Sub
     
    'The form that is called
    Private Sub Form_Load()
     
        Dim MyDimensions() As String
     
        MyDimensions = Split(Me.OpenArgs, ":")
        Me.Move MyDimensions(1), MyDimensions(0)
     
    End Sub
    Any good?
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Oct 2004
    Location
    Oxfordshire, UK
    Posts
    89
    pootle flump I pasted your code into a pair of test forms and it doesn't work for me at all... Should the forms have any particular property values e.g. border type etc.?

  4. #4
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Nope. However one thing did occur to me - all my non-pop ups (and the calling form in this instance) are maximised. Is yours?
    Testimonial:
    pootle flump
    ur codings are working excelent.

  5. #5
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Ok - if I changed my calling form to a pop up I replicated your problem. If I then change the code to the below and set the border style to none then it works again. I think you need to compensate for the border unless there is a way you can read the height of it.

    Code:
    Private Sub Command0_Click()
    On Error GoTo Err_Command0_Click
        Dim intTop As Integer
        Dim intLeft As Integer
        
        intTop = Me.WindowTop + Me.txtBelowMe.Top
        
        intTop = intTop + Me.txtBelowMe.Height
        
        intLeft = Me.txtBelowMe.Left + Me.WindowLeft
        DoCmd.OpenForm "frpPopUpBelowControl", , , , , , intTop & ":" & intLeft
    Exit_Command0_Click:
        Exit Sub
    Err_Command0_Click:
        MsgBox Err.Description
        Resume Exit_Command0_Click
        
    End Sub
    Testimonial:
    pootle flump
    ur codings are working excelent.

  6. #6
    Join Date
    Oct 2004
    Location
    Oxfordshire, UK
    Posts
    89
    The main window and calling form are maximised and the pop-up is a non-maximised form with Popup=True. Changing the border style doesn't affect the position it opens at...

  7. #7
    Join Date
    Oct 2004
    Location
    Oxfordshire, UK
    Posts
    89
    Little bit out of sync with the messages here. Unfortunately the popup form doesn't open at all now... Any ideas?

  8. #8
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    See if the attached works for you.
    Attached Files Attached Files
    Testimonial:
    pootle flump
    ur codings are working excelent.

  9. #9
    Join Date
    Oct 2004
    Location
    Oxfordshire, UK
    Posts
    89
    Thanks for all your hard work pootle flump. I'm sorry to say I'm getting a "method or data member not found" error here:

    'frmOpenPopUpBelowControl
    Private Sub Form_Load()

    Dim MyDimensions() As String

    MyDimensions = Split(Me.OpenArgs, ":")

    Me.Move MyDimensions(1), MyDimensions(0)

    End Sub

    What references were there in the project?

  10. #10
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Coo - written in XP so reference to Access 10. Change this if you are in 2k. Also ADO and OLE which can be removed though I wouldn't expect them to cause a problem.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  11. #11
    Join Date
    Oct 2004
    Location
    Oxfordshire, UK
    Posts
    89
    Ah, that explains it. I'm playing in A2K so this'll not be available to me. It's weird that A2K allowed me to open a XP file with no warnings...try opening A2K file in A97! Ah well, back to the drawing board... Thanks again for all your efforts.

  12. #12
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    there was a whole paradigm shift from 97 to 2k. 2k -> 2003 are much more compatible.

    Don't give up yet. The file is in A2K format - you should just need to change the references. Open up the VBA IDE -> Tools -> References. Any that are marked as MISSING need to be rereferenced to your appropriate ref. Most likely is the Access reference.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  13. #13
    Join Date
    Oct 2004
    Location
    Oxfordshire, UK
    Posts
    89
    Sorry I've not replied sooner - I've been away from all computers for a while (). There aren't any missing references so I'm not sure what's happening.

  14. #14
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Ok.

    Check http://www.peterssoftware.com/winmanip.htm out. The bottom two examples do what you want to do though I haven't looked at the code.
    Testimonial:
    pootle flump
    ur codings are working excelent.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •