I liked the idea of a recent files list showing when the Office Button is clicked. But decided that a better use would be to allow the logged in user to see a list of the most recent purchase orders he/she has created. I first investigated the examples to find out how the “recent files list” is created. I found that the code to create it is in the CommandManager OfficeButton method ”
OnBuildRecentFileList” which defines an array (taItems) as an array with [n,5] elements, where n = the number of lines to display.
The elements hold horizontally:
- 1 = 0
- 2 = “&1 Recent file – 1
- 3 = “Messagebox(“Recent file 1″)
- 4 = “Recent File 1″
- 5 = 0
I concluded that the elements of the array that I was interested in were 2, 3 and 4.
2 holds the text shown in the list. 3 holds an executable script performed when clicked. (The OnClick event), 4 holds the contents of the tooltip.
So now to make all this work. What did I need to achieve.
- Use the Office Button to display the most recent Purchase Order Numbers and make the number of Purchase Order’s shown be adjustable.
- Create form accessible by clicking “Options” after clicking the Office Start Button. Place a spinner on the form to adjust the number shown.
- Store number in a preferences table.
- Amend the code in the onBuildRecentFileList of the OfficeMenu in the main Form.
Use the Office Button to display the most recent Purchase Order Numbers and make the number of Purchase Order’s shown be adjustable.
The new code:
LParameters taItems Local lnCount As Number If !Used("purchaseorders") Use "\\Path to Purchase Orders\purchaseorders.dbf" In 0 Alias PurchaseOrders Shared EndIf If !Used("numbers") Use "\\Path to Purchase Orders\numbers.dbf" In 0 Alias Numbers Shared EndIf Do Case Case ThisForm.lnStatisticsType = 1 Select Numbers lnNumberOfPos = Numbers.RecentPos Dimension taItems[ lnNumberOfPos, ALen( m.taItems, 2)] Select PurchaseOrders Set Filter To PurchaseOrders.nEmployee = ThisForm.nEmployeeNo Goto Bottom For lnCount = 1 To lnNumberOfPos cPoNo = Transform(PurchaseOrders.nPoNo) taItems[ lnCount, 1] = 0 taItems[ lnCount, 2] = "&" + TransForm(lnCount) + " Purchase Order No. - " + cPoNo taItems[ lnCount, 3] = "MessageBox( 'Purchase Order " + cPoNo + "')" taItems[ lnCount, 4] = "Purchase Order - " + cPoNo taItems[ lnCount, 5] = 0 Skip - 1 EndFor Case ThisForm.lnStatisticsType = 2 && Show last Purchase Order No. used etc Case ThisForm.lnStatisticsType = 3 && Show Computer Statistics EndCase Select PurchaseOrders Use Select Numbers Use Return .T.
The above code was also amended to add some other ideas for information to give to the Salesperson and will be revisited when I have time as I want to pull of Computer Statistics etc. The Buttons on the Start Menu simply change the value of
onBuildRecentFileListevent seems to get fired automatically, although the menu closes and the “Office Button” has to be clicked again to see the changes.
I created a small form as shown below to allow the Salesperson to decide how many Purchase Orders they wanted to see in the “recent files list”. At the moment it only shows the number of recent Purchase Orders, but allows for other options to be added. The form is made available by clicking on the “Options Button” shown when clicking the “Office Button”.
My next problem was in getting the Recent files list to pass the Purchase Order Number so that I could open “Purchase Order Edit” with the correct Purchase Order displayed and ready to edit. I found that element 3 of the taItems array held an executable script, so thought to pass the Purchase Order number to a method on the form which would then open up the Purchase Orders Edit form.
As the elements are filled at the time the “Office Button” is clicked I had to create the script on the fly so I wrote the code as:
taItems[ lnCount, 3] = "ThisForm.EditPo(cPoNo)". This line replace the code
taItems[ lnCount, 3] = "MessageBox( 'Purchase Order " + cPoNo + "')".
This gave an error that it could not find cPoNo. The next thing I tried was to make cPoNo public in my “main.prg”. No error but it always passed the first Purchase Order number in the list. So, after sending for help from my FoxPro colleagues Mr Stuart Dunkeld came to my rescue with
taItems[ lnCount, 3] = [ThisForm.EditPo('] + cPoNo + [')].
As a tempory arrangement for testing I had placed the line
MessageBox("PO to edit " + cPoNo)after the lParameters staement. Rebuilt the exe and clciking a number of Purchase Orders I proved that each time a messagebox came up with the correct Purchase Order number each time.
Now to get the Edit form to show with the correct Purchase order shown for editing. This proved quite easy. “main.prg” creates a global object “oGlobal” which I use to pass variables from one form to another. The solution was to Let the “ThisForm.EditPo” method save the Purchase Order Number to oGlobal.nOrderNo. Then call the editing form. Added a few lines of code so that the init in EditPo so that if oGlobal.OrderNo had a PO no. in it then it showed its details otherwise opened blank waiting for a PO no. to be entered.
Code in ThisForm.EditPo below:
Lparameters lcPoNo Local lnPoNo lnPoNo = Val(lcPoNo) oGlobal.nOrderNo = lnPoNo Do Form frmViewEditPoNew Return .T.
Code in the init of frmViewEditPoNew:
Lparameters lcPoNo If !Empty(oGlobal.nOrderNo) .SetForPoKnown() Else .BlankoGlobal() Endif Return .T.
The method ThisForm.SetForPoKnown populates the form with the Purchase Order details whilst the ThisForm.BlankGlobal set the form up with all text boxs etc blank.
It works and I am happy.