Solved

Click a command button from other procedure

Posted on 2007-11-13
10
175 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…

792 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