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
lp3535Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
GrahamSkanConnect With a Mentor RetiredCommented:
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
 
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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
WikkardCommented:
take off the brackets or put the word call in front
ie ButtonOK_Click
or Call ButtonOK_Click()
0
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.