查找过程是否以其他形式运行

时间:2015-08-13 18:53:07

标签: access-vba

我有一个表格X,其中包含以下程序:

Public Sub PrintUT_Click()

If Forms!frmDisclosure.Command280.Visible = True Then
    Forms!frmDisclosure.GoToLastRecord
End If

RemoveSchma
DoCmd.TransferText acExportMerge, "", "qryUndertaking", conAddrPth &   "\DataSource.txt", True, "", 1252
OpenWordDoc

ExecuteFile "E:\Peter\Desktop\Update Service.pdf", printfile

End Sub

从另一个表单(表单Y)从两个命令按钮之一调用它。如果我想要一个按钮,我想要' ExecuteFile" E:\ Peter \ Desktop \ Update Service.pdf",printfile'跑步。如果从另一个按钮调用,我不想要' Exceute ...'跑步。什么'如果......然后'我可以在表单X中设置prodecure来实现这个吗?

1 个答案:

答案 0 :(得分:1)

最简单的方法是添加一个布尔开关作为参数,将例程移出按钮事件并移入其自己的子中。

Private Sub Button1()
RoutineNameHere
End Sub

Private Sub Button2()
RoutineNameHere False
End Sub

Public Sub RoutineNameHere(Optional blnExecute as Boolean=True)
If Forms!frmDisclosure.Command280.Visible = True Then
    Forms!frmDisclosure.GoToLastRecord
End If

RemoveSchma
DoCmd.TransferText acExportMerge, "", "qryUndertaking", conAddrPth &   "\DataSource.txt", True, "", 1252
OpenWordDoc

If blnExecute Then
    ExecuteFile "E:\Peter\Desktop\Update Service.pdf", printfile
End If
End Sub