【问题标题】:MS Access - 2 combo boxes, one isn't updatingMS Access - 2 个组合框,一个未更新
【发布时间】:2011-12-05 06:29:45
【问题描述】:

我在一个表单上有两个组合框。 The first allows the user to search a record by name, and when a record is selected, all of the other controls on the form are updated.我不记得我是怎么做到的,我想可能是通过向导。但是现在我想添加第二个组合框,允许用户按地址搜索,但是当在这个新的组合框中选择地址时,记录不会更新。

这是我尝试过的:

Private Sub Form_Activate()
    Me.Refresh
End Sub

还有……

Private Sub Combo250_AfterUpdate()

Me.Requery

End Sub

还有一个 SearchForRecord 宏,它使用这个 WHERE 子句搜索第一条记录

="[ID] = " & Str(Nz(Screen.ActiveControl,0))

涉及的两个表是 Demographics 和 Addresses,它们通过 ID 列连接。

请帮忙!

【问题讨论】:

    标签: ms-access vba ms-access-2007


    【解决方案1】:

    Use the wizard to add the combobox and when the option shows "Find a record on my form based on the value I select in my combobox", choose that and continue through the wizard.

    手动代码:

    With Me.RecordsetClone
        .FindFirst "Address='" & Me.cboAddress & "'"
        If Not .NoMatch Then
            Me.Bookmark = .Bookmark
        End If
    End With
    

    【讨论】:

    • 我知道我以前见过,但它现在没有在向导中显示为选项。你遇到过这个问题吗?
    • 另外,我知道当记录源为空时这个选项不会显示,但我实际上记录源中有多个表,所以它应该显示
    • @Jerry 您的表单似乎基于 SQL 字符串而不是表或查询,这将产生您遇到的问题。您可以将记录源保存为查询,然后您的向导将再次运行,或者您可以手动创建代码。
    【解决方案2】:

    首先,您应该给控件起有意义的名称,例如cboSearchByAddress

    我不知道 SearchForRecord 宏是如何工作的,但是您可以将 AfterUpdate 事件中的代码更改为:

    Private Sub cboSearchByAddress_AfterUpdate()
      Me.Filter = "[ID]=" & Nz(cboSearchByAddress,0))
      Me.FilterOn = True
    End Sub
    

    您可能需要将 Nz(cboSearchByAddress,0)) 更改为 Nz(cboSearchByAddress.Column(0),0)),具体取决于组合框的设置。

    【讨论】:

      猜你喜欢
      • 2011-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-14
      • 2017-06-15
      • 1970-01-01
      相关资源
      最近更新 更多