Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 2nd, 2007, 11:59 AM
Authorized User
 
Join Date: Oct 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default Determining what field has focus?

I am trying to wright an If statement that will do different thing depending on which field in the form has focus. I don't know what code to use to determine which field has focus.
 
Old November 2nd, 2007, 03:29 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

For each of the controls, add an OnFocus event that sets a global string to the name of the control. In your branching, read that global string:
Code:
Private Sub txtName_GotFocus()

    gstrFocusHolder = "txtName"

End Sub

Private Sub MySub()

    Select Case gstrFocusHolder
        Case "txtName"
        ...
    End Select
[/code]
 
Old November 5th, 2007, 10:10 AM
Authorized User
 
Join Date: Oct 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think I asked the question wrong. I need to know which field had focus just before clicking on another control. I am trying to set up a filtering feature where a user can click on a control within a form and then click a filter button to preform the filter.:)

 
Old November 6th, 2007, 12:30 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

When you move from one control to the next, the control that had the focus just prior to you moving the cursor is obtained by referencing

Screen.PreviousControl.Name

Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old November 6th, 2007, 12:58 PM
Authorized User
 
Join Date: Oct 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for all the help. :)






Similar Threads
Thread Thread Starter Forum Replies Last Post
Determining control that has focus in jscript Bill999 .NET Framework 2.0 1 January 31st, 2007 02:49 PM
Focus on a text input field fizzerchris Classic ASP Basics 0 December 16th, 2005 09:20 PM
Keeping the focus on a field lguzman Access VBA 7 April 20th, 2005 10:18 AM
.showmodaldialog and field focus DarrenMelling Classic ASP Basics 0 February 14th, 2005 06:45 AM
Determining the length of a database field john_reeve41 BOOK: Beginning ASP 3.0 2 February 26th, 2004 12:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.