locked
Need combo box to refresh when moving to new record RRS feed

  • Question

  • I have a form and subform.  Main form displays Employee name, start date, and other general information.  Subform displays data about various training the employee has had.  Typically the form opens up to the first employee (alphabetically) and users click through records to get the employee records they want to view by using the navigation buttons at the bottom of the form.  Works fine.  However, users are now asking me if I can add a combo box to choose the employee and filter the records so they don't have to click through all employees to get to the one they want to view.  They still want the ability to use the navigation buttons too though.  I've added the combo box and it works fine, however if the navigation buttons are used, the data changes accordingly, but the name in the combo box doesn't change.  The user has no idea whose records they are viewing if the name doesn't change as well.  Any way to force that to happen?
    Wednesday, June 30, 2010 4:12 PM

Answers

  • In the OnCurrent event of the main form check to see if the value of the combo box matches the employee in the current record.  If it doesn't then change the value of the combo box to the value in the current record. 

    You may also want to use a form level boolean variable (i.e. fbNoRequey) as a switch that is set to False in Form_Open and set to True if the OnCurrent event changes the value of the combo box.  Assuming you are using the OnChange event in the combo box to select the record put a check to see if the fbNoQuery flag is set to True and if it is skip the code that selects the record and set the fbNoQuery flag to false.

    • Edited by Vanderghast Thursday, July 1, 2010 5:25 PM Changed Talse to False (typo)
    • Marked as answer by Tim Li Thursday, July 8, 2010 8:14 AM
    Wednesday, June 30, 2010 4:25 PM

All replies

  • In the OnCurrent event of the main form check to see if the value of the combo box matches the employee in the current record.  If it doesn't then change the value of the combo box to the value in the current record. 

    You may also want to use a form level boolean variable (i.e. fbNoRequey) as a switch that is set to False in Form_Open and set to True if the OnCurrent event changes the value of the combo box.  Assuming you are using the OnChange event in the combo box to select the record put a check to see if the fbNoQuery flag is set to True and if it is skip the code that selects the record and set the fbNoQuery flag to false.

    • Edited by Vanderghast Thursday, July 1, 2010 5:25 PM Changed Talse to False (typo)
    • Marked as answer by Tim Li Thursday, July 8, 2010 8:14 AM
    Wednesday, June 30, 2010 4:25 PM
  • Seems you use the compobox for two puposes, search for a record and show current record information. I do not fully understand your application. May be your application will be simpler if you use your comboox only to do a search? In the main form you can then add a textbox that shows the info you try to show in the combo.

    I guess your combobox is unbound? Not possible to propose exact code without knowing more

    Use the on current event on the main form. In the form_Current procedure you write the code to handle your combobox

     

    Private Sub Form_Current()

    on error goto Errorhandler
        me.comboboxname.column(0) = something, or set rowsource or what you need

        exit sub

    Errorhandler:
    End Sub

    Be aware that the on current event often runs when you dont expect it to run, for instance when your form opens. You may need an errorhandler. An empty errorhandler allows your code to continue even after an error.

    Because of the unpredictable  triggering of on_currenet event, i often prefere to change behaviour of comboboxes etc when a button is pressed or another event initiated by the operator (user) takes place. Then I use the after_update event for the button, combobox, textfield or whatever.

    Regards from Tore

    • Proposed as answer by Tim Li Thursday, July 8, 2010 8:14 AM
    Wednesday, June 30, 2010 5:43 PM
  • What I do is: in the AfterUpdate event of the combo, un-hide a text box (me.txt.visible = True) that is placed directly in the same spot at the cbo (except leaving the down arrow visible). The text box is bound the field in the subform to display the current info.

    Brad

    Monday, July 19, 2010 7:47 PM