我正在尝试从我的其他形式'frmDisclosure'中以'frmInvoiceAdd'的形式运行一个过程。它不是Form / SubForm关系。它们是分开的。 'frmInvoiceAdd'中的过程是:
CmdInvoice on click:
Public Sub CmdInvoice_Click()
On Error GoTo CmdInvoice_Click_Err
On Error Resume Next
DoCmd.GoToRecord , "", acNewRec
DoCmd.GoToControl "InvDate"
Me.InvDate = Date
DoCmd.RunCommand acCmdSaveRecord
DoCmd.RunSQL "UPDATE tblInvoices SET tblInvoices.DiscFK = [Forms]!
[frmDisclosure]![DiscPK], " & _
"tblInvoices.ClientFK = [Forms]![frmDisclosure]![ClientFK],
tblInvoices.ReceiptFK = [Forms]![frmDisclosure]![ReceiptFK] " & _
"WHERE (((tblInvoices.InvoicePK)=[Forms]![frmInvoiceAdd]!
[InvoicePK])) "
CmdInvoice_Click_Exit:
Exit Sub
CmdInvoice_Click_Err:
MsgBox Error$
Resume CmdInvoice_Click_Exit
End Sub
我正试图通过以下方式从'frmDisclosure'运行它:
DoCmd.OpenForm "frmInvoiceAdd"
Run Forms!frmInvoiceAdd.CmdInvoice_Click
DoCmd.Close acForm, "frmInvoiceAdd"
我收到此错误消息:
Microsoft Access无法找到该过程'。' 它强调: 运行Forms!frmInvoiceAdd.CmdInvoice_Click
我尝试将“运行”更改为“调用”,但收到此错误消息: !预期的:。或(
答案 0 :(得分:2)
要从表单模块外部调用表单模块中的公共子(或函数),请使用以下语法:
Call Form_NameOfTheForm.NameOfTheSub()
在这个例子中:
Call Form_frmInvoiceAdd.CmdInvoice_Click()
答案 1 :(得分:0)
我插了 On Error Resume Next 这解决了这个问题。