Button to Agent

How can this code be changed to work in an agent as opposed to where I currently have it... in a button?  I'd rather have the button trigger the agent.

Sub Click(Source As Button)
      Dim workspace As New NotesUIWorkspace
      Dim uidoc As NotesUIDocument
      Dim doc As NotesDocument
      Dim curdoc As NotesDocument
      Dim db As NotesDatabase
      Dim view As NotesView          
      Dim PartNo As String
      Dim answer As Integer
      Dim codeType As String
      Set uidoc = workspace.CurrentDocument
      If uidoc.IsNewDoc Then
            Set curdoc = uidoc.Document
            Set db = curdoc.ParentDatabase
            Set view = db.GetView("VendorTable")'All Fields Values sorted
            PartNo = uidoc.FieldGetText("ven_num") 'The FieldName you want to check
            Set doc = view.GetDocumentByKey(PartNo)
            If Not (doc Is Nothing) Then
                  Forall i In doc.Items
                        If (i.Text = PartNo) Then codeType = "Vendor Number"
                  End Forall
                  answer = Messagebox( "Duplicate " & codeType & " found. Switch to existing Vendor document?", 1+32, "Duplicate Vendor Document")
                  If (answer = 1) Then
                        curDoc.SaveOptions = "0"
                        Call uidoc.Close          
                        Delete uidoc
                        Call workspace.EditDocument(True, doc)
                  End If
            End If  
      End If      
End Sub
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

If this is an agent that is run in foreground via agent, then you can just copy and paste it in initialize event . And call it from button either using simple action "Run Agent" or ToosRunMacro command

This cannot be a scheduled/background agent.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Put the code in the agent with properties as :

Shared agent

Manually from Agents List

Run Once @Commands May be used.


Paste the code in the initialize event.

Now, create a button and have the

@command([ToolsRunMacro];"AGENT NAME")

to run the agent.  Make sure you use (Agent Name) with in paranthesis since the agent will be hidden in this case.

Good Luck!

schmad01Author Commented:
Thanks alot.  I was pasting it in Declarations, no wonder I was getting errors.
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

You shoudl have been able to paste in (Decalartions), and Notes should have created a new subroutine automatically.  Well, water under the bridge, I guess.
well if you dont have sub initialize and end sub copied into your clipboard then you will get these kinds of errors right ?
Nope, you will just have an empty initialize, and a sub called click that is never executed
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.