By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,702 Members | 1,253 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,702 IT Pros & Developers. It's quick & easy.

Advancing unbound combo box

P: 3
Hello,

I知 sure this is a relatively easy fix, but I have an unbound combo box on a form that runs numerous queries in the After Update section. Everything there works fine. All I need to do is have a command button on the form that advances the focus of the combo box to the next record in the query its row source is based on (plus I知 sure it will need an error catcher when it gets to the end of the list). I know how to advance the form痴 record with a button, but neither the form nor the combo box are bound. I知 sure someone knows off the top of their head, so I thought I would ask, since googling for an hour has turned up no results.

Thanks in advance.
May 21 '07 #1
Share this Question
Share on Google+
4 Replies

JConsulting
Expert 100+
P: 603
Hello,

I知 sure this is a relatively easy fix, but I have an unbound combo box on a form that runs numerous queries in the After Update section. Everything there works fine. All I need to do is have a command button on the form that advances the focus of the combo box to the next record in the query its row source is based on (plus I知 sure it will need an error catcher when it gets to the end of the list). I know how to advance the form痴 record with a button, but neither the form nor the combo box are bound. I知 sure someone knows off the top of their head, so I thought I would ask, since googling for an hour has turned up no results.

Thanks in advance.
for clarity sake...you want to select the first item in the combo box...it runs queries. You push a button and the next item in the combo box is "clicked"...etc...until all items are done.?
May 22 '07 #2

P: 3
for clarity sake...you want to select the first item in the combo box...it runs queries. You push a button and the next item in the combo box is "clicked"...etc...until all items are done.?
Well, my combo box works perfectly and runs all the code that I have set up for it. All I want to do is have a command button that takes the combo box to the next record (in the drop down list) rather than clicking combo, selecting the next record, etc. My form is designed to look through many records so to be able to go to the next record in the combo quickly would be handy. For the button, I don't think I can use:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.GoToRecord , , acNext
because my form is unbound. Somehow I need to reference the combo and have it go to the next record in its list.

Thanks for your help.
May 22 '07 #3

JConsulting
Expert 100+
P: 603
Well, my combo box works perfectly and runs all the code that I have set up for it. All I want to do is have a command button that takes the combo box to the next record (in the drop down list) rather than clicking combo, selecting the next record, etc. My form is designed to look through many records so to be able to go to the next record in the combo quickly would be handy. For the button, I don't think I can use:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.GoToRecord , , acNext
because my form is unbound. Somehow I need to reference the combo and have it go to the next record in its list.

Thanks for your help.
put this in a code module
Expand|Select|Wrap|Line Numbers
  1. Function AdvanceCombo(strForm As String, strControl As String)
  2. 'This function clears all entries on all listboxes on the form strForm
  3. Dim c As Control
  4. Dim F As Form
  5. Dim I As Long
  6. Dim cValue As String
  7. Set F = Forms(strForm)
  8. Set c = F(strControl)
  9. cValue = c.Value
  10. For I = 0 To c.ListCount - 1
  11. If c.ItemData(I) = cValue Then c.Value = c.ItemData(I + 1)
  12. Next I
  13. End Function
  14.  
for your button code
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command15_Click()
  2. AdvanceCombo Me.Name, "cboTest" '<---replace cbotest with your combo name
  3. End Sub
  4.  
J
May 22 '07 #4

P: 3
Shiny! Thanks for your help. I don't think I would have discovered that on my own.

BTW, I had make the button redo the After Update of the combo, because it did not do it automatically, just in case anyone else has a similar problem. The finished button looks like this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdnext_Click()
  2. AdvanceCombo Me.Name, "cboName"
  3. cboName_AfterUpdate
  4. End Sub
Thanks again!
May 22 '07 #5

Post your reply

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