Reputation:
I have a form X with the following procedure:
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
It is called from another form (form Y) from one of two command buttons. If called fom one button I want 'ExecuteFile "E:\Peter\Desktop\Update Service.pdf", printfile' to run. If called from the other button, I don't want 'Exceute...' to run. What 'If... Then' prodecure can I set up in form X to achive this?
Upvotes: 0
Views: 21
Reputation: 696
Easiest way is to add a boolean switch as a parameter, moving the routine out of a button event and into it's own sub.
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
Upvotes: 1