Solved

Click a command button from other procedure

Posted on 2007-11-13
10
169 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

895 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

14 Experts available now in Live!

Get 1:1 Help Now