Results 1 to 5 of 5
  1. #1
    JFord is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2017
    Posts
    5

    Accessing ActiveDatasheet properties when ActiveControl has focus

    I have hijacked the "Query Design Datasheet Cell" right-click context pop-up menu to provide database-specific actions. From there I use the SelTop and SelHeight properties to determine context and take action from there.



    This works about half the time, the other half it appears that it is not the Screen.ActiveDatasheet that has focus, but instead the Screen.ActiveControl and therefore the critical SelTop and SelHeight properties are not available. I cannot determine when this will happen as the exact same actions will have different results.

    Is there anyway to make the datasheet active or to navigate from the ActiveControl to the ActiveDatasheet or other way to determine the currently selected rows?

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,398
    not tested but you can try

    screen.activecontrol.parent to identify the form the activecontrol is on

    Edit: there is also screen.activeform - but this identifies the main form, so if your control is on a subform it will not be correct

    -Mainform - active form
    ----subform
    --------control - active control

  3. #3
    JFord is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2017
    Posts
    5
    Thanks for the reply, Ajax.

    Actually, I am not using a form, I am in the Query result datasheet.

    I have tried using the Parent property, but very few of its properties are populated, including .Name. But I can navigate the object model and get the name of the query (I forget how at the moment, but I am sure that I could find it again), however, I am not sure how to extract what I need even if I do have the name of the query.

    Also, I am not sure why this works sometimes and sometimes not. I have tried clicking around the datasheet to see if I can get it change the behavior, but my only solution is to close the query and reopen it and it works. Then the next time it doesn't, or does, depending on the direction of the wind and how I hold my tongue in my mouth.

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,398
    perhaps explain more clearly what you are trying to do with an example of what your query result looks like (with headers). It sounds suspiciously like you are trying to apply excel methodologies to access - which won't work. Screen.active... is vba which you cannot use in a query except perhaps via a function (in which case, provide the code as well) - and the screen.active... is only active when its window has the focus - so perhaps the reason why it doesn't always work is because you have clicked somewhere else, or some other code/whatever has shifted the focus to another window.

  5. #5
    JFord is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2017
    Posts
    5

    OK, I'm a bonehead

    I wanted to follow-up on this thread so that it didn't remain hanging. After stripping down my code to provide the information you requested I discovered that in certain cases I was destroying the object I was attempting to use along the way.

    Thank you for your support and the impetus to get to the bottom of this.

    This thread should be closed or deleted since there is really nothing to be learned.

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

Similar Threads

  1. DoCmd.GoToRecord , , acGoTo, Screen.ActiveControl
    By hnhpak in forum Programming
    Replies: 6
    Last Post: 04-14-2015, 07:13 AM
  2. Macro for Me.ActiveControl.Dropdown
    By cowboy in forum Macros
    Replies: 1
    Last Post: 10-02-2014, 05:53 AM
  3. Replies: 6
    Last Post: 12-03-2013, 02:59 AM
  4. ActiveControl form Events - VBA
    By Epidural in forum Forms
    Replies: 5
    Last Post: 05-22-2012, 10:44 AM
  5. Help with gotocontrol, activecontrol
    By k9drh in forum Forms
    Replies: 5
    Last Post: 04-21-2011, 10:12 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