我们在聊天讨论后,我嘲笑式的东西,希望看起来像你试图做:
Link to Access file mock-up。
为其他可能读这以后这里有一些澄清:
- 形式Form1中有一个名为Text0它和一个按钮文本框。
- 当按钮被按下时,它应该打开Form2,其上有一个 子窗体。然后
- 窗体2应该打开到一定的记录,然后过滤 记录其子窗体显示在提供的所有应用价值Text0
这里是什么Form1中看起来我的实体模型像:
所以,当我提供了一个引用号,然后单击按钮...
...下面的代码(注释)是该按钮的点击事件中运行:
Private Sub cmdOpen_Click()
' check user has provided a RefNo in the textbox...
If _
Me.Text0 = "" Or _
IsNull(Me.Text0) _
Then
' ...if a RefNo has not been provided, give an error message
MsgBox "Please provide a Ref No.", vbExclamation Or vbOKOnly, "Disclosure Search"
Else
' ...if a RefNo has been provided, look in the table that lists an applicant's
' forms and return the ApplicantID (or equivalent field you're using) for the RefNo provided
Dim varApplicantID As Variant
varApplicantID = DLookup("ApplicantID", "tblRefNos", "RefNo=" & Me.Text0)
' ...check that an applicant record can be actually be found from the RefNo provided
If _
IsNull(varApplicantID) _
Then
'... if an applicant record is not found, give an error message
MsgBox "Could not find an applicant with the RefNo provided.", vbExclamation Or vbOKOnly, "Disclosure Search"
Else
'... if an applicant record is found, open Form2 to that applicant's record
DoCmd.OpenForm "Form2", , , "ApplicantID=" & varApplicantID
'... and then filter the subform on Form2 by the RefNo provided
Forms!Form2!frmApplicantForms_sub.Form.Filter = "RefNo=" & Me.Text0
Forms!Form2!frmApplicantForms_sub.Form.FilterOn = True
Forms!Form2!frmApplicantForms_sub.Form.Requery
End If
End If
End Sub
这将导致窗体2开放来源于正确的申请记录的引用号提供,并且还过滤由引用号提供窗体:
您的具体项目布局可能与我嘲笑的不同,所以有些可能需要针对您的设置进行调整,但希望我在此处演示的原则很容易翻译。
祝你好运!
它没有任何意义。您打开frmDisclosure两次,第二次应用无意义的过滤器。 – Gustav
它使得莫尔感觉可能是明显的。表单披露通常会打开一个筛选器,在我使用的其他代码中,该筛选器必须被删除。“打开两次”可用于其他代码。看来我的'Refce'有错。删除过滤器,我收到一条消息,指出frm Disclosure无法找到。 –
控件的名称是相同的。 –