473,396 Members | 2,033 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,396 software developers and data experts.

Test if a particular field has got focus

4
Hi All
Is there any way to test if a form field has got focus. I have a button that runs code to filters by selection, but if any other field other than the field [MthFwd] is selected i want a message box to appear and tell the user to select a month from the MthFwd field before running the filter. Here is my code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdFBSelection_Click()
  2.  
  3.      Screen.PreviousControl.SetFocus 
  4.  
  5.      'Code to check if MthFwd has focus. If not  then msbbox and exit sub
  6.  
  7.      DoCmd.RunCommand acCmdFilterBySelection 'Runs filter
  8.  
  9.  
  10. End Sub
Thanks in advance for any help

LSteve
Apr 10 '08 #1
4 9861
Stewart Ross
2,545 Expert Mod 2GB
Hi. One way to do what you need to do is to check the name of the control returned by Screen.PreviousControl.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdFBSelection_Click()
  2. Dim Ctrl as Control
  3. Set Ctrl = Screen.PreviousControl
  4. If Ctrl.Name <> "Mthfwd" then
  5.   MsgBox "your message"
  6.   Ctrl.Setfocus
  7.   Exit Sub
  8. end if
  9. DoCmd.RunCommand acCmdFilterBySelection 'Runs filter
  10. End Sub
I am not convinced that this is the right way to go as all it shows is that the last control that had focus was the one mentioned. It does not show that a value has been updated. If you need to ensure that a value has been updated you could use the After Update event for that control to set a value accordingly, then test for this value in your selection code.

As an example, you could set the control's tag property (which is normally unused) to a text value in the control's After Update event code then test for that value in your selection click routine:
Expand|Select|Wrap|Line Numbers
  1. Private Sub MthFwd_AfterUpdate()
  2.   Me!MthFwd.Tag = "Updated"
  3. End Sub
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdFBSelection_Click()
  2. If Me!Mthfwd.Tag <> "Updated" then
  3.   MsgBox "your message"
  4.   Me!MthFwd.Setfocus
  5.   Exit Sub
  6. end if
  7. DoCmd.RunCommand acCmdFilterBySelection 'Runs filter
  8. End Sub
Hope these ideas help.

-Stewart
Apr 10 '08 #2
Stewart Ross
2,545 Expert Mod 2GB
I had a further thought: if all you need to do is to make sure there is a value in Mthfwd to filter upon, why not just test for Mthfwd null?

Expand|Select|Wrap|Line Numbers
  1. If IsNull(Me!Mthfwd) then
  2.   msgbox "no value selected"
  3.   Me!Mthfwd.SetFocus
  4.   Exit Sub
  5. End If
-Stewart
Apr 10 '08 #3
LSteve
4
Thanks Stuart for your help. I now have it working by using your suggestion of using the tag property. When MthFwd had focus i set the tag to a value of 1. when it lost focus it was set to a value of 0. This value is then used to run the relavent code.
There is so much to learn for us newbies.

Thanks again
LSteve
Apr 10 '08 #4
NeoPa
32,556 Expert Mod 16PB
In a form, Me.ActiveControl is the one with the focus. If the one you want to test has a .Name that is different, then it's not got the focus.
Apr 11 '08 #5

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

Similar topics

6
by: Geoff | last post by:
When trying to focus a field in Firefox, I get the following error: Error: " nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "JS frame ::...
2
by: Fred Wilson | last post by:
Hello, How does one go about finding all the tables that have a particular field name? For example a field name "EVENT_CODE" I would like to find all the places in the database this is...
1
by: Will_uk | last post by:
I am trying to return focus to a form input field. If i use <form>.<field>.focus() the focus returns to the field but if the field already contains a value it selects it (blacks it out). Is it...
8
by: ReadEh | last post by:
I am working on a database in Access 97 that contains over 300 tables. I need to produce a list of tables that contain a particular field (e.g all the tables that contain a field called D.O.B). I'm...
1
by: kababoom | last post by:
I'm running Oracle 9i i would like to import one particular field stored in a excel format (which contains many fields) into oracle is there any command i could use to perform this task? Thanks for...
2
by: donpro | last post by:
Hi, I have a form with date fields, I have created event listeners to check for a validate when leaving the field (onblur). If invalid, I need it to set the field back to the default value,...
5
by: bbatson | last post by:
Hello, Suppose I have a form (call it "form1") with two tabs. On tab1 I have a button that I would like to set the focus on a text box, call it "txt1" on a subform (call it "subform1") which is...
1
by: Mark B | last post by:
VB.NET: How do I get the value of a particular field in the currently edited gridview row?
1
by: Jagadeshwar Rao | last post by:
Hai friends, have a great day i am using ms access 2003 in which i created a file with login username and password form(with some simple code not OS login username and password) and made the...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.