how to set focus on field when searching database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nursebadge
    New Member
    • Aug 2013
    • 3

    how to set focus on field when searching database

    Hi
    In a database form I want to be able to highlight a field, select a find and replace control and on entering a search value be able to display the next record satisfying the search criteria with the focus set on the field used in the search. Is this possible please?
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You can use the SetFocus method of a control to give it focus.

    Comment

    • nursebadge
      New Member
      • Aug 2013
      • 3

      #3
      Thanks for your quick reply. Can you let me know how to preserve the db/record/field value so that when the record is found I can use that value in a setfocus command. To be more specific, at present, I select a field in a record, use find&replace to enter the value I want to find; this finds a record which contains the corresponding field with that value but does not set focus on that field.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Can you let me know how to preserve the db/record/field value so that when the record is found I can use that value in a setfocus command.
        I have no idea what that's supposed to mean. The value in a field has nothing to do with focus. Just use SetFocus on the control right after your VBA code that does the find.

        Comment

        • jimatqsi
          Moderator Top Contributor
          • Oct 2006
          • 1290

          #5
          It may be that you can use the PreviousControl property for this purpose. Save the name of the control that had the focus prior to the find/replace control; then set the focus to that control after the find/replace returns.

          This Microsoft link may help.

          Comment

          • nursebadge
            New Member
            • Aug 2013
            • 3

            #6
            I was confusing the boxes on a form containing fields with the fields themselves. Using the PreviousControl property did the trick. Many thanks for your help.

            Comment

            Working...