0

I have two comboboxes on a subform.The first combobox is used to populate the second combobox. These are placed in the detail section of the form. I want them to work this way:when I select any value from the first combobox, I want the second combobox of the same row to get populated by relevant value.

As of now, I have tried to implement this and as I select any value from the first combobox of row 1 I see the second combobox of the same row gets populated but as I go on selecting values from the first set of comboboxes I see that the values in the second set of the comboboxes above changing or becoming null.

Here's the code:

The 1st combobox is cboRCMTask:

Private Sub cboRCMTask_AfterUpdate() 
    Me.cboRCMTaskOptions.RowSource = "SELECT ID, RCMTaskOptions FROM tblRCMTaskOptions WHERE RCM_ID=" & Me.cboRCMTask.Column(0) & ";" 
    Me.cboRCMTaskOptions = Me.cboRCMTaskOptions.ItemData(0) 
    Me.cboRCMTaskOptions.Requery 
End Sub 

cboRCMTaskOptions is the second combobox.

The form_current event:

Private Sub Form_Current() 
    Me.cboRCMTask.RowSource = "SELECT ID, RCMTask FROM tblRCMTask;" 
    If IsNull(txtRCM_ID) Then 
        Me.cboRCMTask = Me.cboRCMTask.ItemData(0) 
    End If 
    Me.cboRCMTaskOptions.RowSource = "SELECT ID, RCMTaskOptions FROM tblRCMTaskOptions WHERE RCM_ID=" &    Me.cboRCMTask.Column(0) & ";" 
    If IsNull(txtRCMOption_ID) Then 
        Me.cboRCMTaskOptions = Me.cboRCMTaskOptions.ItemData(0) 
    End If 
End Sub 
4

2 回答 2

1

根据您的描述,您使用的是连续形式。虽然看起来连续表格有很多行,但从编码的角度来看,您可以认为它只有一行,即当前行。我怀疑组合 2 的控制源是组合中隐藏的数字列,当您更改组合的行源时,无法再找到可见行,因此无法显示。您要么必须提供一个弹出式表单进行编辑,要么提供一个文本框来存储表单的值,并提供一个稍微狡猾的组合来编辑该值。您可以通过条件格式来改善外观。

于 2012-04-23T09:21:44.810 回答
1

在您的第一段代码中,将代码转移到 on_click 事件。我不确定您要通过引用 ItemData 来实现什么,但我认为没有必要,请注释掉该行。

同样,Form_current 事件中的倒数第三行,替换为重新查询。

于 2012-04-23T04:50:52.117 回答