Results 1 to 7 of 7
  1. #1
    loubon is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2018
    Posts
    4

    Use Set Focus in Detail Area after Filter From Header

    Hi all. Not a programmer so I'm not even sure what I'm trying to do is possible. I have a form that has controls and buttons in the Header. These are for filtering specific results which then show in the Detail section. For example, if you fill in the field called Solution ID and click the Search button the Detail area will show all records that match the above. The output in the Detail is columnar not a datasheet format. Some of these fields can be updated others can't. There is also a Clear button in the Header that clears the whole form so you can search again. (The last button just takes you back to the main menu). I used some code I found by Allen Browne to achieve this.



    I was able to modify it so the focus is on the first search (filter) control each time the form is opened or cleared and reset. But in cases where the search is run and the results are shown in the Detail you can't see where the cursor is. I'd like the focus to be on the first editable field but since it is showing results from the filter I'm not sure that is possible. Any attempt I've made to add a set focus line of code either causes an error or messes up the one that always sets it back when first opened or after being cleared.

    Hopefully, that makes sense and TIA.

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,742
    Try setting the focus in the Form_Current event.

  3. #3
    loubon is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2018
    Posts
    4
    That didn't work assuming I followed you correctly. I put me.NameOfField.setfocus in the On Current property. The focus is just on the next button in the header (which is probably where it was before when I couldn't see it). When I tab around it just moves around the Header.

    In case I didn't explain it properly, the Search (filter) is executed by a click of a command button in the header.

  4. #4
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,742
    Can you post a jpg of the form? It isn't clear if your Header/Detail might be a mainform/subform setup. Code treatment for the latter is a bit more complicated than the former.

  5. #5
    loubon is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2018
    Posts
    4
    Definitely not a form and subform. That was the path I took originally and scrapped that when I found this method. Not sure I can post an attachment since I'm new but this is the code I used. The output is similar except for the fact that the results are columnar rather than datasheet. http://allenbrowne.com/ser-62.html

  6. #6
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,742
    Code:
        '***********************************************************************
        'Chop off the trailing " AND ", and use the string as the form's Filter.
        '***********************************************************************
        'See if the string has more than 5 characters (a trailng " AND ") to remove.
        lngLen = Len(strWhere) - 5
        If lngLen <= 0 Then     'Nah: there was nothing in the string.
            MsgBox "No criteria", vbInformation, "Nothing to do."
        Else                    'Yep: there is something there, so remove the " AND " at the end.
            strWhere = Left$(strWhere, lngLen)
            'For debugging, remove the leading quote on the next line. Prints to Immediate Window (Ctrl+G).
            'Debug.Print strWhere
            
            'Finally, apply the string as the form's Filter.
            Me.Filter = strWhere
            Me.FilterOn = True
            ClientID.SetFocus
        End If
    End Sub
    Changed Browne's form default view to single form and added the red, and the clientID in the detail section gets the focus after a search.

  7. #7
    loubon is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2018
    Posts
    4
    Bingo! Thank you so very much! I was so close. I had also changed to single form and added that line exactly where you did. But I had a "me." at the start.

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

Similar Threads

  1. Replies: 3
    Last Post: 11-17-2015, 05:49 PM
  2. Not able to sort in detail area
    By boywonder381 in forum Reports
    Replies: 7
    Last Post: 09-21-2014, 09:44 PM
  3. Detail area of form help
    By Darkmatter5 in forum Forms
    Replies: 1
    Last Post: 07-10-2012, 04:28 PM
  4. Replies: 9
    Last Post: 02-22-2012, 07:30 PM
  5. Sums in Detail area of report
    By Rick West in forum Reports
    Replies: 2
    Last Post: 12-01-2009, 07:15 PM

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