473,473 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Retaining focus

jimleon
74 New Member
To select a field to search i normally get focus on that field and hit CTRL+F, this works fine. I am in the process of stream lining this with a search button. I use a command button that runs a macro that runs RunCommand - Find.
The problem i find is that hitting the command button changes focus from the desired field in the Look In part of the search form. Is there any way of preventing this happening or setting focus to field that was active prior to hitting the button?
Nov 9 '06 #1
4 2569
PEB
1,418 Recognized Expert Top Contributor
Hi this can be done using custom defined menu bar with your respective command

or by using visual basic...

In the After Update event procedure assign to a variable for the form which was the last control

Clicking on the bouton you can move the focus like this

Me!MyControl.SetFocus

So tell us what way do you want to follow?
Nov 9 '06 #2
jimleon
74 New Member
Hi this can be done using custom defined menu bar with your respective command

or by using visual basic...

In the After Update event procedure assign to a variable for the form which was the last control

Clicking on the bouton you can move the focus like this

Me!MyControl.SetFocus

So tell us what way do you want to follow?
I will be using vba to solve this one, but first a few more questions.
I understand about changing the focus and how it is achieved, but to what do I apply the After Update procedure? The button?
Nov 9 '06 #3
missinglinq
3,532 Recognized Expert Specialist
The problem with using Me!MyControl.SetFocus is that you have to hardwire the actual name of the control, so you'd have to have a separate button for each field that you might want to search. Instead, use

Screen.PreviousControl.SetFocus

This will set focus back on whichever control had focus before you clicked on the search button, so you can have one button and search any control. Here's a piece of code I use behind a search button. It opens up the Find dialog box for whatever control had focus last, and searchs Any Part of Field:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Search_Click()
  2.     Screen.PreviousControl.SetFocus
  3.     SendKeys "%ha%n", False
  4.     DoCmd.RunCommand acCmdFind
  5. End Sub
  6.  
Nov 10 '06 #4
jimleon
74 New Member
Many thanks, that worked a treat.

The problem with using Me!MyControl.SetFocus is that you have to hardwire the actual name of the control, so you'd have to have a separate button for each field that you might want to search. Instead, use

Screen.PreviousControl.SetFocus

This will set focus back on whichever control had focus before you clicked on the search button, so you can have one button and search any control. Here's a piece of code I use behind a search button. It opens up the Find dialog box for whatever control had focus last, and searchs Any Part of Field:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Search_Click()
  2.     Screen.PreviousControl.SetFocus
  3.     SendKeys "%ha%n", False
  4.     DoCmd.RunCommand acCmdFind
  5. End Sub
  6.  
Nov 10 '06 #5

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

Similar topics

65
by: SamMan | last post by:
A question came up at work from one of our clients about forms on their site. The data from these forms are processed by a PHP script and if all goes well, a thank you screen appears. Sometimes,...
2
by: Steven T. Hatton | last post by:
I believe the answer is that the language doesn't support the ability to retain a reference to a std::indirect_array<>, and would be illadvised to try, but I figure I'll ask just to be sure. What...
19
by: jeff | last post by:
how do you convert form byte to Int32 while retaining the binary value of the byte array
1
by: noor | last post by:
Hi I have been working since 2 days to device a method to export sql table into csv format. I have tried using bcp with format option to keep the column names but I'm unable to transfer the file...
0
by: Earl Teigrob | last post by:
I have a page that reads values from an XML file to display to the user. The page also has a control panel that allows administrators to update the XML file with new values. When an administrator...
2
by: cFleury | last post by:
This system works in a intranet w/ some 200 stations and this particular form is retaining its values among different stations...like if I enter some values in the form on station 1 walk to station...
2
by: cFleury | last post by:
The forms in my application are retaining the values objects have (text box, datagrid, public vars, etc…) among different computers in the network, for example if you as result of entering a...
1
by: ujjc001 | last post by:
I have a page that has an asp button and smart nav is on. I add "btnPrintServicePlan.Attributes.Add("onclick",...
2
by: s4lin | last post by:
problem is pagination not retaining data field i have form with general data field, and i need to select some option which is store in database, so i open another page with retrieving data from...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.