Solved

Click a command button from other procedure

Posted on 2007-11-13
10
181 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses
Course of the Month7 days, 5 hours left to enroll

622 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