Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 188
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
GrahamSkanCommented:
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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