Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Click a command button from other procedure

Posted on 2007-11-13
10
Medium Priority
?
186 Views
Last Modified: 2010-04-30
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
Comment
Question by:lp3535
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 8

Expert Comment

by:Wikkard
ID: 20276173
You can call an OK click event procedure directly from your main loop.
ie
ButtonOK_Click()
0
 

Author Comment

by:lp3535
ID: 20276210
Hi Wikkard,

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

0
 
LVL 8

Expert Comment

by:Wikkard
ID: 20276254
take off the brackets or put the word call in front
ie ButtonOK_Click
or Call ButtonOK_Click()
0
Industry Leaders: 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!

 
LVL 8

Expert Comment

by:Wikkard
ID: 20276257
When you put parenthesis it expects a return value from a function call.
0
 

Author Comment

by:lp3535
ID: 20276324
Hi Wikkard,

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

0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 2000 total points
ID: 20276681
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
 
LVL 15

Expert Comment

by:JackOfPH
ID: 20276970

YourFormName.ButtonOK_Click
0
 
LVL 8

Expert Comment

by:Wikkard
ID: 20276981
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
 
LVL 8

Expert Comment

by:Wikkard
ID: 20276989
oops without the parens
ViewStock.btnOK_Click
0
 

Author Closing Comment

by:lp3535
ID: 31409122
As usual GrahamSkan, your answer was spot on.

Thanks everyone else for your help.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question