473,385 Members | 1,474 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,385 software developers and data experts.

In Access, can cursor default to the search box on a form?

269 256MB
Is it possible to have the cursor default to the Search box on an Access form when the form is opened? I have several forms that are used for both data entry and viewing. We use the search box a LOT. If someone types something to search, forgetting to put the cursor in the search box, they end up typing over data somewhere.

Would be awesome to put the cursor in the search box on FormOpen...but I haven't found out how, or if it's even possible.

Anyone?

Thank you smart people! :-)
Jan 14 '19 #1

✓ answered by twinnyfo

As I've looked at it, the only thing one can do with the NavigationButtons is set its value to True or False (shown or unshown).

Even though when one clicks into that section, one can tab through the controls (including the little search box), I have found no way to "jump to it" from the Form itself.

20 2349
NeoPa
32,556 Expert Mod 16PB
Rushed - but :
Expand|Select|Wrap|Line Numbers
  1. Call Me.{ControlName}.SetFocus()
should be all you need.
Jan 14 '19 #2
DanicaDear
269 256MB
But it's not my control...it's the Access built-in search box in the navigation bar (I think it's called navigation bar...by the forward and backward arrows at the bottom of the application.)
Jan 14 '19 #3
NeoPa
32,556 Expert Mod 16PB
Actually, now I have a little more time, there are a couple of ways.
  1. If you set the tab order such that the Control you want to go to first is first (.TabStop=True & .TabIndex=0) then it will start there automatically. This is often all that's required.
  2. Otherwise, in either the Form_Open() or Form_Load() event procedures include the line from my earlier post.
    So, if your Control is called {ControlName} then you'd use :
    Expand|Select|Wrap|Line Numbers
    1. Call Me.{ControlName}.SetFocus()
Jan 15 '19 #4
NeoPa
32,556 Expert Mod 16PB
DanicaDear:
I think it's called navigation bar...by the forward and backward arrows at the bottom of the application.
Are you talking about the part of the form at the bottom which is enabled by setting .NavigationButtons to Yes? Sometimes looking like :


I wouldn't describe this as a search box so much as a navigation bar. You can go backwards and forwards using the buttons but you can only enter the positional record number in that box to select a record.

If that is what you mean then I know of no way to navigate to that box I'm afraid.
Attached Images
File Type: jpg Navigation.JPG (3.8 KB, 586 views)
Jan 15 '19 #5
NeoPa
32,556 Expert Mod 16PB
PS. I just noticed we're both coming up to a count of posts that is a ppower of two. You'll probably get to 256 (2^8) before I reach 32,768 (2^15) :-(
Did I mention it's always fun to see your posts :-)
Jan 15 '19 #6
twinnyfo
3,653 Expert Mod 2GB
There is also a search box in the Navigation Control, but I’ve never tried to set focus on it programmatically. I’ve never even thought to try.

I’ll try to take a look at this....
Jan 15 '19 #7
DanicaDear
269 256MB
twinnyfo is winning!
Yes, that's what I'm trying to do. :-)
It would be crazy awesome in a number of programs I've written.

NeoPa, thank you, it's always fun getting the answers I need. LOL!!
Jan 15 '19 #8
twinnyfo
3,653 Expert Mod 2GB
As I've looked at it, the only thing one can do with the NavigationButtons is set its value to True or False (shown or unshown).

Even though when one clicks into that section, one can tab through the controls (including the little search box), I have found no way to "jump to it" from the Form itself.
Jan 15 '19 #9
NeoPa
32,556 Expert Mod 16PB
TwinnyFo:
There is also a search box in the Navigation Control
How about a picture. You've lost me on this one.
Jan 16 '19 #10
twinnyfo
3,653 Expert Mod 2GB
Certainly! Here it is:

Attached Images
File Type: png Search.png (5.2 KB, 641 views)
Jan 16 '19 #11
DanicaDear
269 256MB
twinnyfo and NeoPa, thank you so much for your time! I tried to figure this out several years ago and no luck then either. :-)
Jan 17 '19 #12
twinnyfo
3,653 Expert Mod 2GB
And you have now officially submitted 2^8 posts on Bytes!
Jan 17 '19 #13
Rabbit
12,516 Expert Mod 8TB
An alternative could be to replicate the functionality with your own set of form controls
Jan 17 '19 #14
NeoPa
32,556 Expert Mod 16PB
I found it when I looked at one of my 2010 databases. Most of my work is still in 2003 as that's what my main client uses.
Jan 17 '19 #15
twinnyfo
3,653 Expert Mod 2GB
NoePa,

I guess that owuld explain it....
Jan 17 '19 #16
NeoPa
32,556 Expert Mod 16PB
I asked about this in an MVP group and got a response from one of the Access Product Team (Shane Groff - Many thanks Shane) who said:
Shane Groff:
I don't think we have any command/method to put the focus there, but adding this works for me:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2. SendKeys "%{F5}"
  3. End Sub
Alt+F5 is the shortcut to put the focus in the record count textbox.
From this I worked out you could determine the number of TABs required to move it across (Depends on which of the buttons are available.) and update it to reflect that. On my form, which uses a snapshot recordset (No adding records.), I needed four TABs and came up with :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.     Call SendKeys("%{F5}{TAB}{TAB}{TAB}{TAB}")
  3. End Sub
Jan 18 '19 #17
twinnyfo
3,653 Expert Mod 2GB
I know how ugly SendKeys can be and I think I remember a little birdie telling me to try to avoid this particular function. I've also heard that this method is less reliable on new Windows 10 systems (and can sometimes not work at all).

So.... I've developed an alternate method for this that I sometimes use to automate things that are outside the bounds of normal "MS Office Automation". It functions quite similarly to SendKeys but uses the system dll to work at that level.

Create a new modules called modKeyStrokes:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Public Declare Sub keybd_event Lib "user32" ( _
  5.     ByVal bVk As Byte, _
  6.     ByVal bScan As Byte, _
  7.     ByVal dwFlags As Long, _
  8.     ByVal dwExtraInfo As Long)
  9.  
  10. Declare Function GetKeyState Lib "user32.dll" ( _
  11.     ByVal nVirtKey As Long) As Integer
  12.  
  13. Private Const vk_Tab = &H9   'TAB key
  14. Private Const vk_Alt = &H12  'Alt key
  15. Private Const vk_F5 = &H74   'F5 Key
  16. Private Const vk_KEYUP = &H2 'indicates the key being released
  17.  
  18. Public Function vkTab()
  19.     keybd_event vk_Tab, 1, 0, 0
  20. End Function
  21. Public Function vkTabUp()
  22.     keybd_event vk_Tab, 1, vk_KEYUP, 0
  23. End Function
  24. Public Function vkAlt()
  25.     keybd_event vk_Alt, 1, 0, 0
  26. End Function
  27. Public Function vkAltUp()
  28.     keybd_event vk_Alt, 1, vk_KEYUP, 0
  29. End Function
  30. Public Function vkF5()
  31.     keybd_event vk_F5, 1, 0, 0
  32. End Function
  33. Public Function vkF5Up()
  34.     keybd_event vk_F5, 1, vk_KEYUP, 0
  35. End Function
Now, in your form, when you want to go to the search box:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdGoToSearch_Click()
  2.     Call vkAlt
  3.     Call vkF5
  4.     Call vkF5Up
  5.     Call vkF5Up
  6.     Call vkAltUp
  7.     Call vkTab
  8.     Call vkTabUp
  9.     Call vkTab
  10.     Call vkTabUp
  11.     Call vkTab
  12.     Call vkTabUp
  13.     Call vkTab
  14.     Call vkTabUp
  15.     Call vkTab
  16.     Call vkTabUp
  17. End Sub
I have an extra Tab in there, because my Access also has a "Filter" control that must be skipped over. Keep in mind that you may have to check to see if you are at a new record, because you will need fewer Tab characters if you are.

It may take some experimenting to do exactly what you need, but it should work (it did for me).

Hope this hepps!
Jan 18 '19 #18
NeoPa
32,556 Expert Mod 16PB
Why ?
Jan 18 '19 #19
twinnyfo
3,653 Expert Mod 2GB
I can tell the what--not the why.

When our office first upgraded to Win10, SendKeys worked on my machine and maybe one or two others. But other machines just sat that looking dumb.

After swithing to the alternate method, things worked fine on all machines.

I wish I could 'splain why....
Jan 18 '19 #20
NeoPa
32,556 Expert Mod 16PB
I should say more.

As a general rule I don't like SendKeys(), or any code that relies on the state of something. That said, there are times when it can do what's required. In this case, I would expect that the requirement for being run in the Form_Open() event procedure would/should make its behaviour fairly predictable. It would also have the advantage of being understandable (if somewhat obscure) and readable in one go.

I haven't experienced such issues in Win 10. Not that I question others may. I just don't use it (I didn't just get off the boat ;-) ).

Maybe if I found it didn't work reliably as expected I'd move on to something like your code, but I'd certainly be upset to have to.

I guess the important thing to take away from this is that the only way to put the focus in that box that we know of is to TAB across from the Record Number box on the Navigation Bar, and the only way we know to get there is to use Alt-F5 (somehow).

NB. I have used O/S calls in my code where I absolutely have to, and one even that mimics keystrokes (Bypassing code when opening a database in Access for instance.) but I always try to avoid it if I can.
Jan 19 '19 #21

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

Similar topics

6
by: Jules | last post by:
Hi: I have an Access 97 Search form set up - a couple of combo boxes, a couple of text fields and a command button. I want the command button to run an SQL script and then open the results form....
1
by: Guest | last post by:
I have 2 tables: 1/ English 2/ Deutsch Which is the best way to make form who is going to scan words from table English to get meaning ( translation) from table Deutsch. Of course I need...
9
by: lightning | last post by:
Hi all, I'm not very conversant with the vocabulary of Access, so please ask for clarification if necessary... I am trying to build a search form that allows combinations of search terms. For...
1
by: tamoochin | last post by:
I have a form that registers the user with my website, the form is in farsi language and must use utf-8 standard. I can store data in MS Access and also read it back with any problems. the...
2
by: Mark | last post by:
Hi All, I am creating a music database for a friend and have run into a problem. Within the ALBUM table, I wanted to store the ARTIST_ID rather than the ARTIST_NAME. To do this, I intended to have...
2
by: zandiT | last post by:
Hello everyone i have a mainform called frmMain and it has 2 subforms. the frmMain consists of 2 combo boxes. i want to create a search form whereby the user can choose an option in combo1 and in...
11
by: woodey2002 | last post by:
This problem is driving me crazy. Hello there, i am trying to create a search form for records in my access database. The search form will contain text boxes and a multi select list box. The user...
6
by: mercout | last post by:
Hey, I've been trying to create a search form in access for a while now, searching through books and emails. I have the search form set up with 11 combo box's, 3 text box's, a view button, and a...
9
f430
by: f430 | last post by:
i have been trying to write a search code for a similar database, and i followed all the steps that were provided above, and my code was close to what lightning had but i have added date range in my...
1
by: lorax | last post by:
I am new to this. I am recreating a form from ACCESS 2000 in Access 2010. The problem is that ACCESS no longer allow one to close a form without saving it. Form: a search form that allows people...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: 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: 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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.