Hi,
LAN V8.0.0.8689
Here's what I'd like to do - when an opportunity is "Closed - Won" and after the Move Products To Assets form has done its work - I'd like the Insert Sales Order form to appear automatically.
Right now, the code is doing everything I think it needs to but the Insert Sales Order form does not appear. I don't get any errors. I just get back to the Opportunity Detail view of my now closed opportunity. I'm guessing that the form doesn't like being called outside of the grid but I'm passing all the parameters it needs? What's the proper way to acheive what I'd like to do?
Here's what I've done.
- I've copied and modified the CallAddEditSalesOrderView(strMode) sub from (Opportunity) Order Details into (Opportunity) Close Opportunity.
- I've copied the CheckPrimaryContact(AccountId, OpportunityId) function from (Opportunity) Order Details into (Opportunity) Close Opportunity.
- I've modified the btnOKClick(Sender) sub in (Opportunity) Close Opportunity and inserted CallAddEditSalesOrderView("Add") after AddAccountProductRecords.
This is a copy of the CallAddEditSalesOrderView sub that I've modified. You can see where I've commented out some of the original code. I've checked the contents of the new variables for Account and Opportunity ID's and they're populated as they should be.
Sub CallAddEditSalesOrderView(strMode) 'This sub is a modified copy from the Opportunity Order Details form. Dim objMainView, objDetail, objParent Dim strSalesOrderID
If strStatus = Application.Translator.Localize("Closed - Won") Then 'DNL Only Closed - Won orders need a sales order
Set objMainView = Application.MainViews.Add("System:Add Edit Sales Order", 0, False) 'DNL objMainView.BorderStyle = 3
Set objDetail = objMainView.DetailsView
If strMode = "Add" Then 'DNL strSalesOrderID = Application.BasicFunctions.GetIDFor("SALESORDER") 'DNL objMainView.SetDataMode 1, strSalesOrderID objDetail.CurrentID = strSalesOrderID 'Set the default Account to that of the Opportunity 'Set objParent = frmOrderDetails.Parent.DetailsView 'Change the object parent 'If Not (objParent Is Nothing) Then objDetail.lveBillAccount.Text = GetField("ACCOUNT", "ACCOUNT", "ACCOUNTID = '" & strAcctId & "'") 'DNL objParent.lnkAccount.Text objDetail.lveShipAccount.Text = GetField("ACCOUNT", "ACCOUNT", "ACCOUNTID = '" & strAcctId & "'") 'DNL objParent.lnkAccount.Text objDetail.txtAccountID.Text = strAcctID 'objParent.lnkAccount.LinkID objDetail.txtOpportunityID.Text = strOppID 'objParent.CurrentID objDetail.txtUserID.Text = Application.BasicFunctions.CurrentUserID objDetail.dteOrderDate.DateTime = Date 'End If 'Set objParent = Nothing objDetail.Caption = Application.Translator.Localize("Insert Sales Order") 'Else 'objMainView.CurrentID = grdSalesOrders.GetCurrentField("SALESORDERID") 'DNL 'objDetail.lveBillContact.Text = grdSalesOrders.GetCurrentField("A3_NAMELF") 'DNL 'objDetail.lveShipContact.Text = grdSalesOrders.GetCurrentField("A4_NAMELF") 'DNL 'objDetail.CurrentID = grdSalesOrders.GetCurrentField("SALESORDERID") 'DNL 'objDetail.Caption = Application.Translator.Localize("Edit Sales Order #: ") & grdSalesOrders.GetCurrentField("SALESORDERNUMBER") 'DNL 'objDetail.Caption = LocalizeFmt("Edit Sales Order #: %s", Array(grdSalesOrders.GetCurrentField("SALESORDERNUMBER"))) End If 'Check for account having a contact If CheckPrimaryContact(objDetail.txtAccountID.Text, objDetail.txtOpportunityID.Text) Then objDetail.Script.Init(strMode) 'If objMainView.ShowModal = mrOK Then 'grdSalesOrders.Refresh 'End If Else MsgBox Localize("An account contact is required for sales orders") End If End If
Set objDetail = Nothing Set objMainView = Nothing End Sub |