Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code and a ComboBox

Status
Not open for further replies.

Radman

Programmer
Jan 20, 2000
22
AU
hi there helper,<br><br>I have a combobox with a query as the data source. I need to be able to select the third option in the query by code and then make it appear in the text section of the combobox. So it looks like you used a mouse to select the option form the combo.<br><br>Cheers<br>Radman
 
Radman,<br><br>The only way I have been able to accomplish this is through a macro.&nbsp;&nbsp;You use the send keys command in the macro to perform the following: {F4}{DOWN}{DOWN}{DOWN}{TAB}.&nbsp;&nbsp;In code, set focus on the combo box and call the macro.&nbsp;&nbsp;One unfortunate byproduct of doing this is that it will turn off your caps lock and number lock.<br><br>If anyone knows how to do this without using a macro, (and has gotten it to work) I would love to hear it.&nbsp;&nbsp;The Access Knowledge Base does not seem to indicate there is another way. <p>-Chopper<br><a href=mailto: > </a><br><a href= > </a><br>
 
If you use the SendKeys command in your code, the caps lock and the num lock do not get affected.&nbsp;&nbsp;I used the code:<br><br>Private Sub PreviousField_AfterUpdate()<br>&nbsp;&nbsp;&nbsp;&nbsp;Forms![MyForm].[MyField].Requery<br>&nbsp;&nbsp;&nbsp;&nbsp;SendKeys &quot;{TAB}{F4}{DOWN}+{TAB}&quot;<br>End Sub<br><br>You would need to add a couple {DOWN} commands if you want to use the third selection.
 
Given: your combobox name is cboNames <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;you want to select the third item in the combobox<br><br>you'd use:<br><br>cboNames = cboNames.ItemData(2)<br><br>Since ItemData is a zero based index, you use one number less than the physical location of the selection in the combobox.<br><br>PaulF
 
Actually, it does still affect the caps lock and shift keys when you use the sendkeys command as Serpica has shown, but not for every action.&nbsp;&nbsp;I have a form that I have used the sendkeys as a macro then changed it to a command, and it still turns off the num and caps locks.&nbsp;&nbsp;On another form, I use the send keys command to only send F2 and it does not turn off the num and cap locks.&nbsp;&nbsp;Go Figure... <p>-Chopper<br><a href=mailto: > </a><br><a href= > </a><br>
 
Bravo PaulF, I knew there was a better way to do it.&nbsp;&nbsp;I have played with it before but it never seemed to work just so. <p>-Chopper<br><a href=mailto: > </a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top