我有一个带有未绑定控件的未绑定表单(Text0)。在Text0中输入RefNo。我想打开另一个表单(frmDisclosure),它有一个包含RefNo的子表单(frmRefNosList)。我打开frmDisclosure的代码是: Private Sub Command8_Click()
Dim Refce As Variant
DoCmd.OpenForm "frmDisclosure"
Forms!frmDisclosure.FilterOn = False
Refce = "Forms!frmDisclosure!frmRefNosList.Form!RefNo"
DoCmd.OpenForm "frmDisclosure", acNormal, "", Refce & " = " & Me.Text0, , acNormal
End Sub
答案 0 :(得分:1)
在我们讨论聊天之后,我嘲笑了一些希望看起来像你想要做的事情:
其他可能会在稍后阅读此内容的人会做一些澄清:
这是我的 Form1 模型的样子:
所以当我提供RefNo并点击按钮时......
...在该按钮的click事件上运行以下代码(带注释):
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
这会导致 Form2 打开从提供的RefNo派生的正确的申请人记录,并通过提供的RefNo过滤子表单:
你确切的项目布局可能与我嘲笑的不同,所以有些可能需要针对你的设置进行调整,但希望我在这里说明的原则很容易翻译。
祝你好运!答案 1 :(得分:0)
这不是我想要的答案但是:我创建了一个查询,该查询产生与未绑定表单上的Text0对应的frmDisclosure的ID号。然后,我从未绑定的表单中使用DLookup检索该ID号,并以这种方式打开frmDisclosure。从未绑定的表格中做到这一点会更好。