Help with form onchange code

  • Thread starter Thread starter Bryan Brassell
  • Start date Start date
B

Bryan Brassell

I have the following code:

Private Sub FAFA4_Change()
FAFA5.Value = ""
FAFA5.Requery
FAFA23.Value = ""
FAFA23.Requery
End Sub

The objects are ComboBoxes. My purpose is to have the
second box (FAFA5) popluated based on the choice in the
first box (FAFA4), and so on.

This code works with one major glitch - it applies itself
to all records rather than just the one that was changed.
Thus, if someone changes the choice in ComboBox FAFA4 for
record 2, all the other records also have their other
ComboBoxes cleared and requeried.

How to I modify the code to only apply to the ComboBoxes
for the record that was changed?

Thanks,

Bryan Brassell
 
From your description, it appears that you're using a continuous forms view
for the form, and that the second combo box is unbound? If yes, you cannot
do what you seek easily, because each combo box is actually the same combo
box, not different combo boxes, and what you do to one is done to all.

There are some tricks that can be used to "work around" this, involving
textboxes on top of combo boxes, using the OnCurrent event to change
properties of the combo box, and other similar concepts, but I hesitate to
go into any details until we know more about your setup and what you want to
accomplish and why.

Can you provide more info?
 
This sounds as if you are referring to a continuous form with a combobox. Since
the combobox in each row of the records is just a new view of the same combobox,
you cannot modify the code to do what you want.

There is a workaround using a textbox bound to the value you want to display in
the combobox. The textbox is placed on top of the combobox. Then you add code
to the textbox's On Focus event to move the focus to the combobox when the
textbox gets the focus.

The combobox will still be requeried and all the views of it updated, but you
will see the value of the bound textbox displayed on the screen.
 
You are both correct-it is a continuous form. The purpose
is to have the user go through each record and pick out
the appropriate category/subcategory, etc. Is the text
box answer the best choice? Will it actuall write the
entered data to the table as intended?

Thanks,

Bryan
 
If you bind the textbox to the approprite field in the form's recordsource,
then yes it will save data to the table. However, this method involves
coding to put the value into the textbox on the combo box's AfterUpdate
event, and code to move the focus to the combo box whenever the textbox gets
the focus.
 
Back
Top