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 April 17th, 2006, 11:19 AM
Registered User
 
Join Date: Apr 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to determine which text box has focus

Another question: I have a form with multiple text boxes on it, and I only want to write one program (and not insert the code into the double click event of every text box).

How do I go about determing which text box has the focus?

or any other suggestions would be great.

John
 
Old April 17th, 2006, 06:55 PM
Authorized User
 
Join Date: Jul 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can set on the form open event

Private Sub Form_Open(Cancel As Integer)

'The text box you want available
TextBoxName.SetFocus
TextBoxName.Locked = False
TextBoxName.Enabled = True

'The text box you dont want available
TxtNm.Locked = True
TxtNm.Enabled = False

End Sub

 
Old April 19th, 2006, 02:29 PM
Registered User
 
Join Date: Apr 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can use the ActiveControl property to refer to the control that has the focus at run time together with one of its properties or methods. The following example assigns the name of the control with the focus to the strControlName variable:

Dim ctlCurrentControl As Control
Dim strControlName As String
Set ctlCurrentControl = Screen.ActiveControl
strControlName = ctlCurrentControl.Name

If no control has the focus when you use the ActiveControl property, or if all of the active form's controls are hidden or disabled, an error occurs.

AvGuy





Similar Threads
Thread Thread Starter Forum Replies Last Post
Group box control Tab Focus problem suji C# 0 September 26th, 2008 01:26 AM
Setting Text Box Focus sathish_reddy ASP.NET 1.0 and 1.1 Professional 1 November 22nd, 2006 02:26 AM
list box item moved up and down with focus valentine Classic ASP Basics 0 August 2nd, 2005 07:50 AM
Setting Focus on a Text Box in a Web Form vbmazza VB.NET 1 May 4th, 2005 09:19 AM
How to focus the insertion point in a text box larry Javascript How-To 3 April 2nd, 2004 07:12 PM





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