• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

Click a command button from other procedure

I writing a loop to load a userform if certain criteria are met, but I want to be able to just print the form and close it, then move onto the next item in the loop.

The problem is that the userform waits for me to click on either "ok" or "cancel" before it moves onto the next step.  My code is below.

        Dim myFirst As Object
        Set myFirst = ActiveDocument.CustomDocumentProperties
         
        Dim CurrentItem As ListItem
        Dim CurrentSubItem As ListView
   
        For Each CurrentItem In StockList.ListView1.ListItems
         
        Dim dToday, DHolding As Date
        Dim ddiff As Long
       
        DHolding = CurrentItem.SubItems(2)
        dToday = Date
       
        ddiff = DateDiff("d", dToday, DHolding)
             
        If ddiff < 3 Then
        myFirst.item("xListItem").Value = CurrentItem.Index
        CurrentItem.Bold = True
        ViewStock.Show
       ViewStock.Print
        Unload ViewStock
        Else
        CurrentItem.Bold = False
        End If
        Next
0
lp3535
Asked:
lp3535
1 Solution
 
WikkardCommented:
You can call an OK click event procedure directly from your main loop.
ie
ButtonOK_Click()
0
 
lp3535Author Commented:
Hi Wikkard,

If I do that I get a compile error -  "=" expected.

0
 
WikkardCommented:
take off the brackets or put the word call in front
ie ButtonOK_Click
or Call ButtonOK_Click()
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
WikkardCommented:
When you put parenthesis it expects a return value from a function call.
0
 
lp3535Author Commented:
Hi Wikkard,

That doesn't work either.  I get "Sub or Function not defined".

0
 
GrahamSkanRetiredCommented:
There is no Print method for a user form. I suppose that you are using PrintForm.

However the Show method defaults to modal. Make it non-modal, thus

       ViewStock.Show 0
       ViewStock.PrintForm
0
 
JackOfPHCommented:

YourFormName.ButtonOK_Click
0
 
WikkardCommented:
You need to call the function (on ViewStock form) that handles the OK button

ie ViewStock.btnOK_Click()
or you can just close the for directly after you print it

ie.
ViewStock.PrintForm
unload ViewStock
0
 
WikkardCommented:
oops without the parens
ViewStock.btnOK_Click
0
 
lp3535Author Commented:
As usual GrahamSkan, your answer was spot on.

Thanks everyone else for your help.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now