473,382 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

SetFocus

Using Access '97 and newer versions as well.

Hi there, am wondering if someone can please explain how and when you would use SetFocus when developing a form.

Am also wondering if it is wise to have SetFocus on each of the controls in a form or just specific ones.

Thank you VERY much for your assistance.
Aug 10 '07 #1
5 1830
Rabbit
12,516 Expert Mod 8TB
Using Access '97 and newer versions as well.

Hi there, am wondering if someone can please explain how and when you would use SetFocus when developing a form.

Am also wondering if it is wise to have SetFocus on each of the controls in a form or just specific ones.

Thank you VERY much for your assistance.
You only use setfocus if you want a certain object to gain control after a certain event. Otherwise you can just use tab order to provide natural flow.
Aug 10 '07 #2
abolos
65
Using Access '97 and newer versions as well.

Hi there, am wondering if someone can please explain how and when you would use SetFocus when developing a form.

Am also wondering if it is wise to have SetFocus on each of the controls in a form or just specific ones.

Thank you VERY much for your assistance.

Suppose you have a combobox in the header of the form and you have many textboxes in the detail. If you want to have the combobox in the header to be selected when running the form, then you have to use the setfocus command.

For the textboxes, whenever you want to use the value or the text that the textbox contains, then you must use the setfocus. ex. if using <SELECT ... WHERE textbox=??>, then you have to setfocus the textbox beforet the SQL statement.

Abolos
Aug 11 '07 #3
missinglinq
3,532 Expert 2GB
Abolos, your response to this post runs the gamut from simply being confusing to being flat out wrong!

Your reference to using setfocus in order to send the focus to a combobox in the header of the form sounds as if this is a special function of setfocus, when in fact, as Rabbit said, it is used to send focus to any control that can receive focus, using VBA code.

While it is true that you have to set focus on a textbox before using the .text property of that control, you do not have to do this when you want to use the .value property! This, plus the fact that .value is the default property of textboxes, is the reason that the .text property is generally only used for a very limited purpose, when the contents of a textbox has to be accessed before the content has been saved. Because .value is the default property for textboxes, instead of coding, say

MyVariable = MyTextBox.Value

you can simply use

MyVariable = MyTextBox.

Lastly, you absolutely do not have to setfocus to a textbox before referring to it's value in a SQL statement! You simply have to use the proper syntax for referring to it.

As Rabbit said "You only use setfocus if you want a certain object to gain control after a certain event. Otherwise you can just use tab order to provide natural flow."

While you normally move from control to control according to how you've set up your Tab Order, there may be times when you want the order to change depending on , for instance, what is entered in a control. Say you have a contact form for customers who call a service hotline when they have problems. You may want a means of contacting them at a later date to see if their problem has been resolved, so you have a control named ContactMethod. You could use code like this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub ContactMethod_AfterUpdate()
  2.   If ContactMethod = "email" Then EmailAddress.SetFocus
  3.   If ContactMethod = "phone" Then PhoneNumber.SetFocus
  4. End Sub
If your CSR person fills in the ContactMethod with "phone" the focus moves automatically to the field where the phone number needs to be filled in; if "email" is filled in, the focus moves to the EmailAddress field so that this data can be entered. Notice that the contents of the textbox ContactMethod is referred to without using .Value and without setting focus to the textbox!

Linq ;0)>
Aug 11 '07 #4
abolos
65
Abolos, your response to this post runs the gamut from simply being confusing to being flat out wrong!

Your reference to using setfocus in order to send the focus to a combobox in the header of the form sounds as if this is a special function of setfocus, when in fact, as Rabbit said, it is used to send focus to any control that can receive focus, using VBA code.

While it is true that you have to set focus on a textbox before using the .text property of that control, you do not have to do this when you want to use the .value property! This, plus the fact that .value is the default property of textboxes, is the reason that the .text property is generally only used for a very limited purpose, when the contents of a textbox has to be accessed before the content has been saved. Because .value is the default property for textboxes, instead of coding, say

MyVariable = MyTextBox.Value

you can simply use

MyVariable = MyTextBox.

Lastly, you absolutely do not have to setfocus to a textbox before referring to it's value in a SQL statement! You simply have to use the proper syntax for referring to it.

As Rabbit said "You only use setfocus if you want a certain object to gain control after a certain event. Otherwise you can just use tab order to provide natural flow."

While you normally move from control to control according to how you've set up your Tab Order, there may be times when you want the order to change depending on , for instance, what is entered in a control. Say you have a contact form for customers who call a service hotline when they have problems. You may want a means of contacting them at a later date to see if their problem has been resolved, so you have a control named ContactMethod. You could use code like this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub ContactMethod_AfterUpdate()
  2.   If ContactMethod = "email" Then EmailAddress.SetFocus
  3.   If ContactMethod = "phone" Then PhoneNumber.SetFocus
  4. End Sub
If your CSR person fills in the ContactMethod with "phone" the focus moves automatically to the field where the phone number needs to be filled in; if "email" is filled in, the focus moves to the EmailAddress field so that this data can be entered. Notice that the contents of the textbox ContactMethod is referred to without using .Value and without setting focus to the textbox!

Linq ;0)>

Thanks linq for the explanation and sorry for making things this way.
Aug 13 '07 #5
missinglinq
3,532 Expert 2GB
Just trying to help you as well as the original poster!

Linq ;0)>
Aug 13 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: amy | last post by:
I have a text box, after user input the value, a validate function trigered. if the value is invalid, alert display, and also set focus back to this control. The alert displays, but when the...
4
by: Mad Scientist Jr | last post by:
i am trying to set focus to a specific control depending on the outcome of a validator control and it is not working. none of these methods are working to setfocus: 1....
8
by: Shachar | last post by:
Hi All, I need to start a new process calc for example and when ever the user click on the button the application should setfocus to the calc application. I use this code but it is NOT...
0
by: MrsLeigh | last post by:
I have a datagrid on a web page. In the footer there is a field that should be recieve the focus, either at the start or after a button is clicked to insert the row that is being added in the...
3
by: Jim Devenish | last post by:
In my application vehicles arrive and depart from a workshop. The ArrivalDate and the HandoverDate are each entered. Sometimes the person who should enter the arrival date forgets to do so. ...
12
by: Michael R | last post by:
TabCtrl --- ..............Tab1--Subform1 ..............Tab2--Subform2---TabCtrl2---Tab21 ..........................................................---Tab22...
0
by: srinivasarao yarru | last post by:
hi sir, in access 2003 how we can use the setfocuse property(we have to lostfocuse from one field with in that we have to setfocuse in same field) i am using this code but not setfocuse...
3
by: srinivasarao yarru | last post by:
hi in access 2003 how we can use the setfocuse property(we have to lostfocuse from one field with in that we have to setfocuse in same field) i am using this code but not setfocuse to same field...
5
agroover
by: agroover | last post by:
I can't seem to figure out how to get rid of the errors. I recieve the following error when I leave the Grade.SetFocus in my code... Microsoft Access can't move the focus to the control Grade ...
3
by: ckrows | last post by:
I have a main form with a button that makes a subform visible. I added a button in the form footer of the subform that is supposed to hide the subform. This does not work because the focus is on...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.