No, but I will try it right now.
I tried it, but it still gave me a double message box. That got me thinking that I may have a more indepth problem with the logic of my code (and not just a problem with Throwfocus and @MsgBox), and it seems that I was correct. I went back in and fixed my logical flow error, but the end of the code still gives me a double line entry on my Writeln message.
PS - Below I'm adding the entire code for this 'on element change'. It's a lot of code (my apologies!), but perhaps my error is further up the line. The execution of this one element is really my main lynchpin for abandoning Q&A (the ability to automatically in real time update Pricing records based upon changes in ItemCost). *********************************** [size=8]// updates Inventory record to reflect cost changes, POdate, PO#, VendorID. // also, if cost has changed, then Pricing records are updated automatically, utilizing different mechanisms depending on whether cost went up or down.
#include "sbasic_include.sbas" //this group of var's is for XResultSet to get Inventory current fields to post to Inventory Last fields var vLastCost as money var vLastPOQty as double var vLastPOAvail as string var vLastPONum as string var vLastPODate as date var vLastVendor as string
//this group of var's is for XResultSet to post data to Inventory record var vRS as Int var vItemCCost as Money var vItemqQty as double var vItemAvail as string var vPONum as string var vPODate as date var vVendor as string
// this group is for the writing of line items ordered to the SummaryView MultiLine field var vTemp as Int var vLine as String var vItemNum as String var vItemQty as String var vItemUoM as String var vItemDesc as String var vSumView as String var vSumView1 as String
// this group is for Pricing - if cost has changed, find all records with this ItemNum // and update Pricing!ClientPrice using new POLines!ItemCost and Pricing!Margin var vPprice as double var vMarg as double var vRecordTotal as int var vPM as string var vLoop as int var vPriceDate as date var vlastPcost as double var vlastPclientprice as double var vlastPpricedate as date var vlastPponum as string var vlastPmargin as double var vItemCustPriceID as string var vEmail as int var vPAN as string var vCostShadow as money
// this group is for figuring pricing if Margin/Normal client and also if Protected/Contract client var vNC as money var vOC as money var vDC as double var vCSP as double var vPSP as double var vPrice as money var vNmarg as double var vPrice4 as money var vPrice5 as money var vMarg4 as double var vMarg5 as double
var vCount as Int var vLoopT as Int var vTotal as Double var vPOTotal as Double
vItemNum = ItemNum vItemQty = ItemQty vItemUoM = ItemUoM vItemDesc = ItemDesc vPAN = "Y" vCostShadow = CostShadow vItemCCost = ItemCost
// Prevent Extend Mode NotifyForm(7)
If (@Mode() < 2) and (@IsBlank(POLinesYN) = 0) and (POLinesYN <> "Y") { WriteLN("Only a 'Y' is permitted in this Placed? field.","Close this window and try again.") Clear(POLinesYN) ThrowFocus(POLinesYN) } // ELSE
If ((@Mode() = 1) or (@Mode() = 0)) and (POLinesYN = "Y") and (ItemCost = CostShadow) { // this XResult section below posts line item data to Inventory record vRS = @XResultSetSearch(@FN, "Inventory", SEARCH_MODE_AND,SEARCH_SYNTAX_QA, "!ItemNum=" + @Str(ItemNum)) If vRS > -1 { //Confirm exactly one matching record If @XResultSetTotal(vRS) = 1 { //Confirm I can change the Inventory record If @XResultSetLocked(vRS) = 0 { // Get the current field info in Inventory in order to post it to the 'Last' fields in Inventory vLastCost = @XResultSetValue(vRS, "ItemCurrentCost") vLastPOQty = @XResultSetValue(vRS, "CurrentPOQty") vLastPOAvail = @XResultSetValue(vRS, "CurrentPOAvail") vLastPONum = @XResultSetValue(vRS, "CurrentPONum") vLastPODate = @XResultSetValue(vRS, "CurrentPODate") vLastVendor = @XResultSetValue(vRS, "CurrentVendor") // Get the current relevant field info from POLines to post in Current fields in Inventory vItemCCost = ItemCost vItemqQty = ItemQty vItemAvail = ItemAvail vPONum = PONum vPODate = @FormFieldValue("Purch", "PODate", 0) vVendor = @FormFieldvalue("Purch", "VendorID", 0) // Post/Set the existing PO data in Inventory from 'current' to 'last' XResultSetValue(vRS, "LastCost", vLastCost) XResultSetValue(vRS, "LastPOQty", vLastPOQty) XResultSetValue(vRS, "LastPOAvail", vLastPOAvail) XResultSetValue(vRS, "LastPONum", vLastPONum) XResultSetValue(vRS, "LastPODate", vLastPODate) XResultSetValue(vRS, "LastVendor", vLastVendor)
// Post/Set the data in POLines to the 'current' data fields in Inventory XResultSetValue(vRS, "ItemCurrentCost", vItemCCost) XResultSetValue(vRS, "CurrentPOQty", vItemqQty) XResultSetValue(vRS, "CurrentPOAvail", vItemAvail) XResultSetValue(vRS, "CurrentPONum", vPONum) XResultSetValue(vRS, "CurrentPODate", vPODate) XResultSetValue(vRS, "CurrentVendor", vVendor) } Else { @MsgBox("Error: Inventory record is locked by another user.","","") } } Else { @MsgBox("Error: There must be only one matching Inventory record.", "", "") } XResultSetClose(vRS) //Close the Inventory Xresult set
// this below section is for POTotals and Saving when the Record ItemCost = CostShadow
// this next section is for the Summary field
vLine = vItemNum + " ** " + vItemQty + " " + vItemUoM + " ** " + vItemDesc + @Newline() + "==========" + @Newline() POLstr = vLine FormFieldValue("POLines", "Saved", 0, 1) @Save If (Saved <> "Y") { ThrowFocus(ItemCost) } If (Saved = "Y") { //ThrowFocus(AddNewItem) vTotal = 0 vCount = @FormResultSetTotal("POLines")
vLoopT = 1 While vLoopT <= vCount { vTotal += @ToNumber(@FormFieldValue("POLines", "LineItemTotal", vLoopT)) vLoopT += 1 }
If vTotal > 0 { FormFieldvalue("Purch", "POTotal", 0, vTotal) }
Writeln("The Last line item has been placed. Unless you wish to add another line item, close this window and then Press the 'Save this PO after Placing' on main PO form") //ThrowFocus(AddNewItem) //@Msgbox("The Last line item has been placed.", "Unless you wish to add another line item,", "Press the 'Save this PO after Placing' on main PO form") } } // this closes the Inventory calcs of If ItemCost = CostShadow section
Else { @MsgBox("Error: Cannot open XResultSet.", "", "") }
} // this closes the #1 Section - If ItemCost = CostShadow
// this next section is for the Inventory calc and also the Pricing database calcs in the event that a new ItemCost // is different than the previous ItemCost
If ((@Mode() = 1) or (@Mode() = 0)) and (POLinesYN = "Y") and (ItemCost <> CostShadow) { // this XResult section below posts line item data to Inventory record vRS = @XResultSetSearch(@FN, "Inventory", SEARCH_MODE_AND,SEARCH_SYNTAX_QA, "!ItemNum=" + @Str(ItemNum)) If vRS > -1 { //Confirm exactly one matching record If @XResultSetTotal(vRS) = 1 { //Confirm I can change the Inventory record If @XResultSetLocked(vRS) = 0 { // Get the current field info in Inventory in order to post it to the 'Last' fields in Inventory vLastCost = @XResultSetValue(vRS, "ItemCurrentCost") vLastPOQty = @XResultSetValue(vRS, "CurrentPOQty") vLastPOAvail = @XResultSetValue(vRS, "CurrentPOAvail") vLastPONum = @XResultSetValue(vRS, "CurrentPONum") vLastPODate = @XResultSetValue(vRS, "CurrentPODate") vLastVendor = @XResultSetValue(vRS, "CurrentVendor") // Get the current relevant field info from POLines to post in Current fields in Inventory vItemCCost = ItemCost vItemqQty = ItemQty vItemAvail = ItemAvail vPONum = PONum vPODate = @FormFieldValue("Purch", "PODate", 0) vVendor = @FormFieldvalue("Purch", "VendorID", 0) // Post/Set the existing PO data in Inventory from 'current' to 'last' XResultSetValue(vRS, "LastCost", vLastCost) XResultSetValue(vRS, "LastPOQty", vLastPOQty) XResultSetValue(vRS, "LastPOAvail", vLastPOAvail) XResultSetValue(vRS, "LastPONum", vLastPONum) XResultSetValue(vRS, "LastPODate", vLastPODate) XResultSetValue(vRS, "LastVendor", vLastVendor)
// Post/Set the data in POLines to the 'current' data fields in Inventory XResultSetValue(vRS, "ItemCurrentCost", vItemCCost) XResultSetValue(vRS, "CurrentPOQty", vItemqQty) XResultSetValue(vRS, "CurrentPOAvail", vItemAvail) XResultSetValue(vRS, "CurrentPONum", vPONum) XResultSetValue(vRS, "CurrentPODate", vPODate) XResultSetValue(vRS, "CurrentVendor", vVendor) } Else { @MsgBox("Error: Inventory record is locked by another user.","","") } } Else { @MsgBox("Error: There must be only one matching Inventory record.", "", "") } XResultSetClose(vRS) //Close the Inventory Xresult set }
vRS = @XResultSetSearch(@FN, "pricing", SEARCH_MODE_AND,SEARCH_SYNTAX_QA, "!ItemNum=" + @Str(ItemNum)) If vRS > -1 { vRecordTotal = @XResultSetTotal(vRS) vPODate = @FormFieldValue("Purch", "PODate", 0) for vLoop = 1 to vRecordTotal XResultSetCurrentPosition(vRS, vLoop) vItemCCost = ItemCost vCostShadow = CostShadow vMarg = @XResultSetValue(vRS, "Margin") vPprice = @XResultSetValue(vRS, "ClientPrice") vPM = @XResultSetValue(vRS, "PriceOrMargin") vPODate = @FormFieldValue("Purch", "PODate", 0) vPONum = @FormFieldValue("Purch", "PONum", 0) vItemCustPriceID = @XResultSetValue(vRS, "ItemCustPriceID") //Confirm I can change the Pricing record If @XResultSetLocked(vRS) = 1 { @MsgBox("Error: Pricing record is locked by another user.","","") } else { If vPM = "M" and (vItemCCost > vCostShadow) //new cost is more then old cost, margin and normal clients have pricing automatically adjusted, based upon ItemCost { // this section takes current info in Pricing and plugs it into Last Pricing fields
vlastPclientprice = @XResultSetValue(vRS, "ClientPrice") vlastPmargin = @XResultSetValue(vRS, "Margin") vlastPcost = @XResultSetValue(vRS, "Cost") vlastPpricedate = @XResultSetValue(vRS, "PriceDate") vlastPponum = @XResultSetValue(vRS, "PONum") vPODate = @FormFieldValue("Purch", "PODate", 0) vPONum = @FormFieldValue("Purch", "PONum", 0)
XResultSetValue(vRS, "LastClientPrice", vlastPclientprice) XResultSetValue(vRS, "LastMargin", vlastPmargin) XResultSetValue(vRS, "LastCost", vlastPcost) XResultSetValue(vRS, "LastPriceDate", vlastPpricedate) XResultSetValue(vRS, "LastPONum", vlastPponum)
// this section takes current cost and calcs new pricing data/margins/costs
vMarg = (vMarg * 1.03) XResultSetValue(vRS, "Cost", vItemCCost) vPprice = (vItemCCost/(1-vMarg)) XResultSetValue(vRS, "ClientPrice", vPprice) XResultSetValue(vRS, "Margin", vMarg) XResultSetValue(vRS, "PriceDate", vPODate) XResultSetValue(vRS, "PONum", vPONum) XResultSetValue(vRS, "ItemDesc", vItemDesc) } If vPM = "M" and (vItemCCost < vCostShadow) //new cost is less than old cost, margin and normal clients have pricing automatically adjusted, based upon ItemCost { // this section takes current info in Pricing and plugs it into Last Pricing fields
vlastPclientprice = @XResultSetValue(vRS, "ClientPrice") vlastPmargin = @XResultSetValue(vRS, "Margin") vlastPcost = @XResultSetValue(vRS, "Cost") vlastPpricedate = @XResultSetValue(vRS, "PriceDate") vPODate = @FormFieldValue("Purch", "PODate", 0) vPONum = @FormFieldValue("Purch", "PONum", 0)
XResultSetValue(vRS, "LastClientPrice", vlastPclientprice) XResultSetValue(vRS, "LastMargin", vlastPmargin) XResultSetValue(vRS, "LastCost", vlastPcost) XResultSetValue(vRS, "LastPriceDate", vlastPpricedate) XResultSetValue(vRS, "LastPONum", vlastPponum)
// this section takes current cost and calcs new pricing data/margins/costs
vNC = vItemCCost vOC = vCostShadow vDC = (vOC - vNC) vCSP = vDC/vOC vPSP = (vCSP * .4) vPprice = (vPprice * (1 - vPSP)) vNmarg = ((vPprice - vNC)/vPprice) XResultSetValue(vRS, "Cost", vNC) XResultSetValue(vRS, "ClientPrice", vPprice) XResultSetValue(vRS, "Margin", vNmarg) XResultSetValue(vRS, "PriceDate", vPODate) XResultSetValue(vRS, "PONum", vPONum) XResultSetValue(vRS, "ItemDesc", vItemDesc) }
If vPM = "P" and (ItemCost < CostShadow) // Protected clients - costs and dates and margin get updated, but not pricing - decision maker // is notified of these Price Attention Needed accounts at the end of the day { // this section puts current Price info into Last Price fields, updates cost, date, new margin, NoteField, but not ClientPrice
vPrice4 = @XResultSetValue(vRS, "ClientPrice") vlastPmargin = @XResultSetValue(vRS, "Margin") vlastPcost = @XResultSetValue(vRS, "Cost") // vlastPpricedate = @XResultSetValue(vRS, "PriceDate") vlastPponum = @XResultSetValue(vRS, "PONum") vPODate = @FormFieldValue("Purch", "PODate", 0) XResultSetValue(vRS, "LastMargin", vlastPmargin) XResultSetValue(vRS, "LastCost", vlastPcost) // XResultSetValue(vRS, "LastPriceDate", vlastPpricedate) XResultSetValue(vRS, "LastPONum", vlastPponum)
// this section puts new cost, calcs new marg and plugs in, and inserts message in PricingNoteField
XResultSetValue(vRS, "Cost", vItemCCost) vMarg4 = ((vPrice4 - vItemCCost)/vPrice4) XResultSetValue(vRS, "Margin", vMarg4) XResultSetValue(vRS, "PONum", vPONum) XResultSetValue(vRS, "ItemDesc", vItemDesc) XResultSetValue(vRS, "PricingNoteField", ("Cost went down to " + @str(vItemCCost) + " on " + vPODate)) }
If vPM = "P" and (vItemCCost > vCostShadow) // Protected clients - costs and dates get updated, but not pricing and margin - // decision maker is notified of these Price Attention Needed accounts at the end of the day // right now via email, but in production it will call a Report that lists the Items, // old cost, new cost, and Pricing records for each Item { // this section puts current Price info into Last Price fields, updates cost, date, new margin, NoteField, but not ClientPrice
// this section reads the data it needs and defines variables vPrice5 = @XResultSetValue(vRS, "ClientPrice") vlastPmargin = @XResultSetValue(vRS, "Margin") vlastPcost = @XResultSetValue(vRS, "Cost") vlastPpricedate = @XResultSetValue(vRS, "PriceDate") vlastPponum = @XResultSetValue(vRS, "PONum") vPODate = @FormFieldValue("Purch", "PODate", 0) vPONum = @FormFieldValue("Purch", "PONum", 0)
// this section plugs in current pricing data into "previous" pricing data
XResultSetValue(vRS, "LastMargin", vlastPmargin) XResultSetValue(vRS, "LastCost", vlastPcost) // XResultSetValue(vRS, "LastPriceDate", vlastPpricedate) XResultSetValue(vRS, "LastPONum", vlastPponum)
// this section updates cost, margin, NoteField, and prints a page that cost has gone up on a Protected Pricing Record
XResultSetValue(vRS, "Cost", vItemCCost) vMarg5 = ((vPrice5 - vItemCCost)/vPrice5) XResultSetValue(vRS, "Margin", vMarg5) XResultSetValue(vRS, "PricingNoteField", ("Cost went up to " + @str(vItemCCost) + " on " + vPODate)) // XResultSetValue(vRS, "PriceDate", vPODate) XResultSetValue(vRS, "PONum", vPONum) XResultSetValue(vRS, "ItemDesc", vItemDesc) //vEmail = @sendmail("smtp.wordcom.com", "PriceActionNeeded","lseale@wordcom.com","lseale@wordcom.com","lksseven@gmail.co m","","Item cost on " + vItemCustPriceID + " went up to " + @STR(vItemCCost)) //NewPage(850, 1100) //PrintString("For this Price Proteced client record " + vItemCustPriceID + ", Item Cost has increase from " + vCostShadow + " to " + vItemCCost + ". Price analysis is needed.", 12, 24, 0, " ARIAL", 12, 0) //FinishPage() XResultSetValue(vRS, "PAN", vPAN) } } // end of the Else calc next XResultSetClose(vRS) // below is the continuation of first If POLinesYN = "Y" condition. It should calc running POTotal // and then save the record, and then go to next record, or if last record, then Write Message // that this was the last record on the PO
// this next section is for the Summary field
vLine = vItemNum + " ** " + vItemQty + " " + vItemUoM + " ** " + vItemDesc + @Newline() + "==========" + @Newline() POLstr = vLine FormFieldValue("POLines", "Saved", 0, 1) @Save If (Saved <> "Y") { ThrowFocus(ItemCost) } If (Saved = "Y") { //ThrowFocus(AddNewItem) vTotal = 0 vCount = @FormResultSetTotal("POLines")
vLoopT = 1 While vLoopT <= vCount { vTotal += @ToNumber(@FormFieldValue("POLines", "LineItemTotal", vLoopT)) vLoopT += 1 }
If vTotal > 0 { FormFieldvalue("Purch", "POTotal", 0, vTotal) }
Writeln("The Last line item has been placed. Unless you wish to add another line item, close this window and then Press the 'Save this PO after Placing' on main PO form") //ThrowFocus(AddNewItem) //@Msgbox("The Last line item has been placed.", "Unless you wish to add another line item,", "Press the 'Save this PO after Placing' on main PO form") } } // this closes the Pricing calcs of If ItemCost <> CostShadow section
Else { @MsgBox("Error: Cannot open XResultSet.", "", "") }
} // this closes the #2 Section - If ItemCost <> CostShadow[/size]
|