Results 1 to 9 of 9
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919

    Is there an API "out there" that will return X,Y for control in detail section


    I have a date control in a continuous form for which I'd like to get its "Y" coordinate in the controls OnClick event. There's no calendar popup in A2003 so I use Browne's popup and want to set the popup's "Top" to align the calendar to the date control.

    Is there an API that can return the x,y coordinates within the main form? (The X coordinate is essentially a constant as related to the date control.)

  2. #2
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,818
    Yes there is. I've never used it, but a solution was posted in this forum: https://www.accessforums.net/forms/o...sor-23837.html = see posts 4 and 6 for sure.
    Assuming you intend to position the top of the calendar at the top of the control being clicked on, you will have to know if there is enough real estate left to show the calendar when the user clicks near the bottom of the detail section. I think you would have to know the height of the form window and compare it to the x? coordinate of the mouse click and calculate if there's enough room left. If not, you will have to line up the bottom of the calendar form, probably by subtracting the height of the form during the Form.Move method.

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    I believe all controls have a Top and Left property. Using VBA, the unit of measurement is twips.
    Code:
    Dim lngTop As Long
    Dim lngLeft As Long
    lngTop = Me.ControlName.Top
    lngLeft = Me.ControlName.Left
    Debug.Print "Top = " & lngTop
    Debug.Print "Left = " & lngLeft

  4. #4
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919
    https://www.accessforums.net/forms/op...sor-23837.html = see posts 4 and 6

    I don't understand the magic number "15". I thought the API returned x,y relative to the Access window.

  5. #5
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,446
    I believe all controls have a Top and Left property
    they do. They also have a height and width property so the top right of a control is left+width. The top and left properties of a control are relative to the form.

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I don't understand the magic number "15". I thought the API returned x,y relative to the Access window.
    See:
    http://visualbasic.ittoolbox.com/gro...pixels-5324564
    http://www.vbforums.com/showthread.p...ixels-to-twips
    http://vbcity.com/forums/t/5030.aspx

  7. #7
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919
    API apiGetWindowRect worked perfectly to resolve my questions. It took a few minutes to discover that the API functions GetXCursorPos() and GetYCursorPos() return the coordinates in Pixels, so one has to convert them to twips to be consistent with any other values expressed in twips as calculations follow. There are 15 twips per pixel.
    Thanks,
    Bill

    Code:
    Option Compare Database
    Option Explicit
    
    Private Type POINTAPI
        X As Long
        Y As Long
    End Type
    
    Type RECT_Type
        left As Long
        top As Long
        right As Long
        bottom As Long
    End Type
    
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Declare Function apiGetWindowRect Lib "user32" Alias "GetWindowRect" (ByVal hWnd As Long, lpRect As RECT_Type) As Long
    
    Public Function GetXCursorPos() As Long
        Dim pt As POINTAPI
        GetCursorPos pt
        GetXCursorPos = pt.X
    End Function
    
    Public Function GetYCursorPos() As Long
        Dim pt As POINTAPI
        GetCursorPos pt
        GetYCursorPos = pt.Y
    End Function

  8. #8
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,818
    Thanks for posting the code; I'll be sure to take a look at it later, but it's getting late here now. Hope you didn't spend too long figuring out about the conversion - the info is in the second link that ssanfu provided! Good luck with the rest of your project.

  9. #9
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919
    The code originated in one of the threads that both you and June7 made reference. As I recall, the thread was quite old. And no, it wasn't a big deal to discover that the API returns pixels after I inquired about the "magic" number 15.
    Thanks for your help,
    Bill

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 04-13-2013, 04:38 PM
  2. Column sum works in "Detail" but not "Footer"
    By Doodlebug2000 in forum Reports
    Replies: 1
    Last Post: 12-10-2012, 03:20 PM
  3. Replies: 2
    Last Post: 11-14-2012, 04:47 PM
  4. Replies: 3
    Last Post: 06-29-2012, 08:54 AM
  5. Replies: 6
    Last Post: 08-11-2011, 10:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums