Access VBADiscuss 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
I'm sorry, one more thing. Is there any event for when the user clicks on the arrow(I don't see one). I want the whole thing to be queried then so that in the begining it's not blank and so that later when a user clicks on it it doesn't only display T or whatever was last queried.
I guess if nothing else, I can put a button on top of it and make a look like the arrow...
When it requeries, the next thing is supposed to be setting the SelStart and SelLength. This is supposed to put the cursor after the "P" (the first letter) and select the rest of the text. I got the impression this worked in your first test. If it is not working on your larger form it may be that the requery is taking more time (and other events are occuring) while you execute setting SelStart and SelLength. By the time the requery has actually finished, your SelStart and SelLength were set but the requery resets the values.
One thing that may help is to put a DoEvents statement in after your requery. DoEvents causes your code to "wait" while everything else (in all of Windows, not just Access) has a chance to do what they need to do. Be aware that it doesn't actually "wait". It releases control to "allow" other things to happen. But the other things have to want to happen at the instance the DoEvents is executed. You may want to execute DoEvents several times in a row to make sure everything else is done before you set SelStart and SelLength. This will slow the process down a little. But maybe not by as much as when you have all of the names in the list.
I'm not aware of an event that monitors when someone clicks the dropdown (the arrow). I'm assuming the trouble is that you don't have a RowSource until the user presses a letter. Two possible solutions for your situation... Use the GotFocus event. This will work if they click the dropdown without tabbing to the field. However, that event also executes if they tab to the field.
The other idea is to initially set up the combobox as a "value list" containing all the letters (A;B;C;..;Z) and numbers (0;1;2;..;9). Then if the user clicks the dropdown, and selects a letter it will be very similar to just typing the first letter. You'll have to remember to set your RowSource type back to "Table/Query" before you set the RowSource to your Select SQL statement. You could use the GotFocus event to set the combobox to a value list. (Remember to execute the requery after setting the value list to refresh the list.)
Thanks, that solved that problem!
At what point does the combobox take the value of the text inside it?
I think after update, which is a problem. How can I access what the user typed in?
This is the problem. Let's say the user types T, all the t's are queried and it drops. The user selects one, let's say Tara. The value of the combobox is now Tara so that if the user deletes Tara and types in A (so that it should query all the A's) the value of the combobox is still Tara! I am going crazy trying all the events and nothing seems to work properly.
Thank you so much for your help, I now got the whole thing working. And it really is so much faster. The only problem now is the arrow, if the user presses it before typing when they load the form it the combo is blank! I don't want to do the set focus thing. I think I'm going to try to creat a button on top of it which will comver it up and when the user presses it it will query the whole db, I'll let you know if that works.
Oh boy, I have decided to change it to a txtbox, listbox, and button because of this problem. I have not seen a way to slove it.
My new method works great except one thing. The listbox doesn't have the properties selstart and sellength. So I'm back to that problem! ANy suggestions?
Ok, sorry I keep posting but I think now I finally got it to work. I went back to the combobx(didn't like the other method) and on Mouse down I check if the combobx is blank. If it is I query the whole db, if not then I don't.