【发布时间】:2015-08-20 00:32:26
【问题描述】:
我在 MS Access 2003 中创建的数据库出现问题。我创建了一个包含两个组合框(cboCategory 和 cboSubCategory)、一个文本框(txtDescription)和一个子表单(sbfExistingItems)的表单。 cboSubCategory 字段是唯一不需要的字段。我在 txtDescription 的 GotFocus 事件中添加了以下代码:
Private Sub txtDescription_GotFocus()
Dim sql As String, child As String, master As String
sql = "SELECT id, description, category, sub_category FROM tblItems"
If IsNull(Me!cboCategory) Or Me!cboCategory = "" Then
' leave recordsource unfiltered
ElseIf IsNull(Me!cboSubCategory) Or Me!cboSubCategory = "" Then
sql = sql & " WHERE [category] = '" & Me!cboCategory & "'"
child = "category"
master = "cboCategory"
Else
sql = sql & " WHERE [category] = '" & Me!cboCategory & "' AND [sub_category] = '" & Me!cboSubCategory & "'"
child = "category;sub_category"
master = "cboCategory;cboSubCategory"
End If
sql = sql & " ORDER BY [description];"
Me!sbfExistingItems.Form.RecordSource = sql
Me!sbfExistingItems.LinkChildFields = ""
Me!sbfExistingItems.LinkMasterFields = ""
Me!sbfExistingItems.LinkChildFields = child
Me!sbfExistingItems.LinkMasterFields = master
End Sub
如果我在没有最后四行的情况下运行它,它可以正常工作(即,子窗体的 RecordSource 设置)。但是,一旦 txtDescription 获得焦点,在最后四行 with 运行它会导致运行时错误 3314(描述不能包含 Null 值),就好像我试图离开主窗体时所需的 txtDescription 字段为空。
为什么主窗体允许我编辑子窗体的 RecordSource 属性而不是它的 LinkChildFields/LinkMasterFields 属性?
【问题讨论】:
-
我创建了一个模型,但找不到问题;这是我的文件供您查看,以防您发现不同之处:drive.google.com/file/d/0B-J5B7nFljZiUHNxeldMcV9Iam8/…
标签: ms-access vba ms-access-2003