使用组合框过滤子表单

发布于 2024-07-25 07:34:21 字数 816 浏览 9 评论 0原文

这花了我将近两周的时间,我不知道还能做什么。 我有一个主表单(UserSearch),它有一个子表单(TestUserSub)。 两种形式的关联表是 tblusers。 很简单; 在主窗体(UserSearch)上,我有一个与 tblusers 中的字段关联的组合框,例如 cmbid、cmbname、cmbdept 等。 我想要的只是让用户从这些组合框中进行选择,并将关联的字段显示在子表单(TestUserSub)中。 我在几个组合框中的更新后事件中尝试了几个不同版本的代码,但子表单中没有发生任何事情,或者在其他情况下我收到错误消息。 我尝试过的一个例子是过滤运行 SQL 命令

Private Sub cmbid_AfterUpdate()

    Dim strSQL As String

    If IsNull(Me.cmbaccess) Then
        Me.RecordSource = "tblusers"
    Else
        strSQL = "SELECT tblUsers.[Team Member_ID] FROM tblUsers " & _
             "WHERE (((tblUsers.[Team Member_ID])= " & [form_testusersub].[txtid2]))& ";"       
        Me.RecordSource = strSQL
    End If

End Sub

上面的方法不起作用...有人可以帮我解决这个问题吗? 我有一个示例数据库,我一直在使用它,并且通过某种非常奇怪的方式,他们成功地在不调用任何代码的情况下完成了同样的事情。 这可能吗?

This has taken me nearly 2 weeks and I don't know what else to do. I have a main form (UserSearch) that has a subform (TestUserSub). The associated table for both forms is tblusers.
very simple; on the main form (UserSearch) I have a ComboBox associated with the fields in the tblusers eg cmbid, cmbname, cmbdept and so on. All I want, is for a user to make a selection from any of these comboboxes and for the associated fields to display in the subform (TestUserSub). I have tried several different versions of code in the after update event in a couple of the ComboBoxes and nothing is happening in the subform or in other instances I get error message.
One example i have tried is filtering running an SQL command

Private Sub cmbid_AfterUpdate()

    Dim strSQL As String

    If IsNull(Me.cmbaccess) Then
        Me.RecordSource = "tblusers"
    Else
        strSQL = "SELECT tblUsers.[Team Member_ID] FROM tblUsers " & _
             "WHERE (((tblUsers.[Team Member_ID])= " & [form_testusersub].[txtid2]))& ";"       
        Me.RecordSource = strSQL
    End If

End Sub

The above didn't work... Can someone please help me with this. I have a sample database that I have been working off of and by some very strange way, they have managed to do this same thing without calling any code. Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

单身情人 2024-08-01 07:34:21

我能够使用下面的示例找出代码

Private Sub yourcombobox_AfterUpdate()
    Dim LSQL  As String

    If IsNull(Me.yourcombobox.Value) Then
        Form_yoursubform.RecordSource = "tablename"
        Me.yoursubform.Requery
        requerysubform 'macro to requery the whole form
    Else
        LSQL = "select * from tablename"
        LSQL = LSQL & " where field= '" & yourcombobox & "'"

        Form_yoursubform.RecordSource = LSQL
        requerysubform 'macro to requery the whole form

    End If
End Sub

希望这会有所帮助。

I was able to figure out the code using the sample below

Private Sub yourcombobox_AfterUpdate()
    Dim LSQL  As String

    If IsNull(Me.yourcombobox.Value) Then
        Form_yoursubform.RecordSource = "tablename"
        Me.yoursubform.Requery
        requerysubform 'macro to requery the whole form
    Else
        LSQL = "select * from tablename"
        LSQL = LSQL & " where field= '" & yourcombobox & "'"

        Form_yoursubform.RecordSource = LSQL
        requerysubform 'macro to requery the whole form

    End If
End Sub

hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文