我试图从另一个表单中调用一个表单Private Sub,当我运行它时,我得到Run-time error 424: Object Required
。错误代码是位于末尾的Call frm_Main.add_arg(filt_key, filt)
Private Sub btn_go_to_pat_Click()
Dim filt_key As String
Dim filt As String
filt_key = "cont_hist_filter"
filt = "MRN = " & Me.MRN
DoCmd.OpenForm "frm_Main"
Call frm_Main.add_arg(filt_key, filt)
End Sub
目标子是:
Public Sub add_arg(arg_key As String, arg_value As String)
MsgBox "Received arg_key " & arg_key & " with value " & arg_value
my_args.Add arg_key, arg_value
End Sub
答案 0 :(得分:1)
表单类的名称为Form_<form name>
,就像您在VBE的项目浏览器中看到的那样。
所以你需要
Call Form_frm_Main.add_arg(filt_key, filt)
或
Dim fMain As Form_frm_Main
Set fMain = Forms!frm_Main
Call fMain.add_arg(filt_key, filt)