Microsoft Access组合框覆盖第一条记录

时间:2014-07-16 14:15:55

标签: sql ms-access combobox ms-access-2010

我有一个包含4名员工的组合框

ID       EmployeeNumber        FirstName        LastName
1        010101                Joshua           Dalley
2        020202                Jessica          Daze
3        030303                Jason            Bruyere
4        040404                Jeremy           Bob

当我显示组合框时,一切看起来都很正常。我有一个onChange()代码,它更新firstName / lastName文本框

Private Sub cboEmployeeNo_Change()
    Me.txtFirstName.Value = Me.cboEmployeeNo.Column(2)
    Me.txtLastName.Value = Me.cboEmployeeNo.Column(3)
End Sub

我的问题是,当我关闭我的表单frm_login时,当我选择了任何ID时,似乎总是会覆盖第一个ID = 1并且在组合框中选择了最后一个员工。我不知道如何解决这个问题。它只更改FirstName和LastName,而EmployeeNumber保持不变。

实施例

ID       EmployeeNumber        FirstName        LastName
1        010101                Jason            Bruyeye
2        020202                Jessica          Daze
3        030303                Jason            Bruyere
4        040404                Jeremy           Bob

如果我在查看ID = 3

时将其关闭,这将是我的表格
Default View: Single Form
Allow Form View: Yes
Allow Datasheet View: No
Allow PivotTable View: No
Allow PivotChart View: No
Scroll Bars: Neither
Record Selectors: No
Navigation Buttons: No
Border Style: Thin

Record Source: tbl_employee

Allow Filters: No
Allow Edits: Yes
Allow Deletions: No
Allow Additions: No
Data Entry: No

1 个答案:

答案 0 :(得分:1)

您的第一个疑惑可能是将表单的Recordsource设置为tbl_employee。您可以使用tbl_employee中的值加载组合框。我在你的问题中看不到任何导致我相信表格应该有Recordsource的内容。

您可以将文本框的控制源设置为组合框的值。

  1. 右键单击txtFirstName - >属性 - >数据 - >控制来源: cboEmployeeNo.Column(2)
  2. 右键单击txtLastName - >属性 - >数据 - >控制来源: cboEmployeeNo.Column(3)
  3. 来自Microsoft Support Article

    To display the *YourField* column of the current combo box selection, create a text box control. Make the text box a calculated control by defining the following expression as the ControlSource for the text box
    =[cboControlName].Column(1)
    where cboControlName is the name of the combo box. The Column property makes the text box (calculated control) read-only.