Solved

Click a command button from other procedure

Posted on 2007-11-13
10
167 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
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
 
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

762 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now