使用组合框过滤子表单
这花了我将近两周的时间,我不知道还能做什么。 我有一个主表单(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能够使用下面的示例找出代码
希望这会有所帮助。
I was able to figure out the code using the sample below
hope this helps.