lp3535
asked on
Click a command button from other procedure
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.CustomDocum entPropert ies
Dim CurrentItem As ListItem
Dim CurrentSubItem As ListView
For Each CurrentItem In StockList.ListView1.ListIt ems
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
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.CustomDocum
Dim CurrentItem As ListItem
Dim CurrentSubItem As ListView
For Each CurrentItem In StockList.ListView1.ListIt
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").
CurrentItem.Bold = True
ViewStock.Show
ViewStock.Print
Unload ViewStock
Else
CurrentItem.Bold = False
End If
Next
ASKER
Hi Wikkard,
If I do that I get a compile error - "=" expected.
If I do that I get a compile error - "=" expected.
take off the brackets or put the word call in front
ie ButtonOK_Click
or Call ButtonOK_Click()
ie ButtonOK_Click
or Call ButtonOK_Click()
When you put parenthesis it expects a return value from a function call.
ASKER
Hi Wikkard,
That doesn't work either. I get "Sub or Function not defined".
That doesn't work either. I get "Sub or Function not defined".
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
YourFormName.ButtonOK_Clic
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
ie ViewStock.btnOK_Click()
or you can just close the for directly after you print it
ie.
ViewStock.PrintForm
unload ViewStock
oops without the parens
ViewStock.btnOK_Click
ViewStock.btnOK_Click
ASKER
As usual GrahamSkan, your answer was spot on.
Thanks everyone else for your help.
Thanks everyone else for your help.
ie
ButtonOK_Click()