Wrox Programmer Forums
|
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 March 25th, 2005, 07:33 AM
Authorized User
 
Join Date: Mar 2005
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default Set focus question


I have two controls: txtQa1 and txtQa2. TxtQa2 is disabled by default and it will be enabled only if the txtQa1.value=2. I have some code on "OnExit" event of txtQa1 which will enable txtQa2 if txtQa1=2. I set consecutive values for Tab index ( 36 for txtQa1 and 37 for txtQa2) but the focus is not set on txtQa2 after exiting txtQa1.
I want to know if it is posible to move focus to txtQa2 without VBA code like "txtQa2.setfocus".
 
Old March 25th, 2005, 08:32 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Put your code to enable txtQa2 on the After Update event of txtQa1, not on On Exit, then the tab order should work on exit.

And why wouldn't you want to use VBA? You are already using it this far, why not another line of code?

mmcdonal
 
Old March 25th, 2005, 09:10 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 248
Thanks: 0
Thanked 1 Time in 1 Post
Default

I messed around with the idea of using an expression like:

=iif([txtQA1]=2,txtQa2.visible=True,txtQa2.Visible=false)

For the txtQA1 AfterUpdate event. Apparently you can't set the visible property from an expression.

mmcdonal is right. You should use the AfterUpdate event instead of OnExit.

I would set the Visible property AND txtQa2.Setfocus. Then your tab order won't matter.

Randall J Weers
Membership Vice President
Pacific NorthWest Access Developers Group
http://www.pnwadg.org
 
Old March 25th, 2005, 10:36 AM
Authorized User
 
Join Date: Mar 2005
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your responses. It seems to work right with AfterUpdate event . The idea is that I have thousands of controls which I have to enable and I use the same function from the module section.This is the reason which determined me not to use supplementary VBA code (like "SpecificControl.SetFocus") but to use TabIndex property. Thanks again!
 
Old March 25th, 2005, 09:38 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 248
Thanks: 0
Thanked 1 Time in 1 Post
Default

Ah ha! This is one of the reasons I thought you might be asking this question! This is why you should be specific about your problem (as BrianWren has suggested in other posts).

Write a procedure in your code. I'm not sure the exact code you'll use since it is dependent on your field names. But you'll do something like

Code:
Private Function HandleTab()

' The following assumes all fields are named using txtQAnnn format
intFiledNumber = Mid(Screen.ActiveControl.Name,6) 
If Me.Controls("txtQA" & intFieldNumber) = ??? then
    Me.Controls("txtQA" & intFieldNumber + 1).Visible = True
    Me.Controls("txtQA" & intFieldNumber + 1).SetFocus
End If

End Function
For each field that you need that code, in the AfterUpdate event put

=HandleTab()

QED

NOTE: This code has not be tested.

Randall J Weers
Membership Vice President
Pacific NorthWest Access Developers Group
http://www.pnwadg.org





Similar Threads
Thread Thread Starter Forum Replies Last Post
set focus sameer_1981 Intro Programming 1 February 27th, 2007 09:14 AM
Set Focus on a Sub Form Brendan Bartley Access 5 September 9th, 2005 10:49 AM
set focus akibaMaila VB.NET 2002/2003 Basics 1 July 12th, 2005 05:56 PM
how to set focus waley .NET Web Services 1 May 25th, 2004 02:38 PM





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