Results 1 to 10 of 10
  1. #1
    PeakH is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    143

    Is it possible to anchor a shortcut menu to the control that opens it instead of the cursor?

    I have a button on a form that opens a small shortcut menu. I would like the menu to be anchored to the bottom of the control so that it always appears in the same spot, instead of wherever the cursor is. Basically I want it to work similarly to the buttons at the top of this forum, like under "Quick Links", the menu starting with "Unanswered Threads" is anchored to the bottom left corner of the "Quick Links" button.



    The following is the code for the menu:

    Code:
    Sub SortPopupMenu()
        Dim SortMenu As CommandBar
        Dim SortBy As CommandBarControl
        
            Set SortMenu = CommandBars.Add("", msoBarPopup, , True)
            Set SortBy = SortMenu.Controls.Add:  SortBy.Caption = "Product Type": SortBy.OnAction = "SortByProduct"
            Set SortBy = SortMenu.Controls.Add:  SortBy.Caption = "Strain Name": SortBy.OnAction = "SortByStrain"
            Set SortBy = SortMenu.Controls.Add:  SortBy.Caption = "Order Entered": SortBy.OnAction = "SortByItem"
            Set SortBy = SortMenu.Controls.Add:  SortBy.Caption = "Custom Sort": SortBy.OnAction = "SortByCustom"
        
        SortMenu.ShowPopup
            
    End Sub
    
    
    Sub SortByProduct()
        Screen.ActiveReport.OrderBy = "[ProdType]"
        Screen.ActiveReport.OrderByOn = True
    End Sub
    
    
    Sub SortByStrain()
        Screen.ActiveReport.OrderBy = "[StrainName]"
        Screen.ActiveReport.OrderByOn = True
    End Sub
    
    
    Sub SortByItem()
        Screen.ActiveReport.OrderBy = "[InfoID]"
        Screen.ActiveReport.OrderByOn = True
    End Sub
    
    
    Sub SortByCustom()
        Screen.ActiveReport.OrderBy = "[Sort]"
        Screen.ActiveReport.OrderByOn = True
    End Sub
    Then the code for the form control:

    Code:
    Private Sub Command246_Click()
        SortPopupMenu
    End Sub

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    SortMenu.ShowPopup has x and y as parameters. Set these to the position (in pixels) of where you want the popup to show.

  3. #3
    PeakH is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    143
    This works great if the user has the database open to full screen, but if they have it sized to partial screen the menu shows up off of the database window. Is there a way to have it follow the window or anchor it to access instead of the monitor somehow?

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Maybe you can use relative positions from: Me.WindowTop/Left/Height/etc

  5. #5
    PeakH is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    143
    hmm. Any ideas of how to work that in?
    The internet seems to be working against me today so researching how to refer to positions has not yielded much good information.
    I have tried working it into the x,y for the Show Popup

    SortMenu.ShowPopup Reports!rptOrderConfPS1!Command246.Height, Reports!rptOrderConfPS1!Command246.Width

    I tried Top and Left, WindowTop and WindowLeft, Windowheight and Windowwidth, but none of those combinations seemed to move the shortcut. Height and Width move the menu, but I'm not sure how it's calculating where to move it and again it is anchored to the monitor screen and not the access window.
    I'm not sure if I can use Me. since I'm not actually doing anything with the report, just referring to a position of a control.

  6. #6
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    I have a button on a form that opens a small shortcut menu
    That is where the "Me" comes in, not sure why you are referencing a report? The attributes are for the Access window, so unless it is a form that can move around the top for the x/y should be static. In this case, the only variable is if the ribbon is maximized or not.

  7. #7
    PeakH is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    143
    My bad, I have a nearly identical button on a report and I am working on both of them. But I did try to do the same thing on the form using Forms!frmLotList!Command58.Top/Left and WindowTop/Left/Height/Width. It is certainly changing where the menu shows up, but not in relation to the access window.

    The form is not popup, but if the access window is moved or resized, the x,y still acts as if it's anchored to the monitor.

    If I use "Me" in the ShowPopup x, y I get an error that says it's an invalid use of "Me" My guess for why would be that the shortcut menu code is not directly on the form control, just called from it?

    So from there I wouldn't know where to put the Me. so that it is valid.

  8. #8
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    I think I have pulled a brain muscle! I found this code and have to admit I don't get what it is doing. However, I did manage to bastardize it sufficiently to make it work. It gets the position of the form and then I add a number to that to mark the position of the menu. You will have to work out your own number to add.

    http://access.mvps.org/access/forms/frm0042.htm
    Attached Files Attached Files

  9. #9
    PeakH is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    143
    Wow! This is wonderful! Thank you so much.

    In order to make both one for the form and another for the report I made a second MoveToTopRight function: MoveToTopRightrpt() and copied it exactly but changed the
    With fwForm
    .hWnd = Forms("frmLotList").hWnd

    To
    With fwReport
    .hWnd = Reports("rptOrderConfPS1").hWnd

    I may try changing it to IF the report is loaded THEN .hWnd= Reports("rptOrderConfPS1").hWnd ; ELSE IF the form is loaded THEN .hWnd = Forms("frmLotList").hWnd
    That way I may be able to create additional buttons like this more easily in the future, but for now I'm thrilled that it works!

  10. #10
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Me too! You can clean it up a bit, change the names and stuff like that. I was just so glad to get it working ... finally.

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

Similar Threads

  1. Custom shortcut menu ?
    By Lukael in forum Access
    Replies: 3
    Last Post: 02-08-2016, 11:50 AM
  2. Anchor pages in tab control
    By snoopy2003 in forum Programming
    Replies: 2
    Last Post: 03-24-2012, 08:26 AM
  3. Anchor control to bottom of detail section
    By talley in forum Reports
    Replies: 0
    Last Post: 04-04-2011, 10:29 AM
  4. custom shortcut menu help!
    By ninachopper in forum Access
    Replies: 5
    Last Post: 09-05-2010, 06:27 AM
  5. Shortcut that ONLY opens Access Form
    By uneek78 in forum Forms
    Replies: 0
    Last Post: 03-30-2009, 06:52 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