locked
Screen button to set values on entity and open new screen RRS feed

  • Question

  • Hey everyone,

    I have created a button on a screen and when the user click the button I want it to change to of the values on the currently selected item and then open another screen to create a new record. This is working with the exception of one item. I can't set the value for one of the fields on the selected item that is a FK relationship to another table.

    Here is the code I have for the button method

     Private Sub ConvertToSale_Execute()
    ' changes opportunity stage to OppStageID=4 "Signed Invoice"
    ' Sets the Probablity to 100% for funnel calculations
    ' saves the opportunity and then creates a new sale record and opens SalesRecordAddEdit screen
    ' passing the ContactID from the opportuniy and the description
                Me.Opportunities.SelectedItem.OppStage.OppStageID = 4
                Me.Opportunities.SelectedItem.Probablity = 100
                Application.ShowSalesRecordAddEdit(Nothing, Me.Opportunities.SelectedItem.Contact.ContactID, Me.Opportunities.SelectedItem.Contact.Account.AccountID)
            End Sub

    This is the part that is not working...

    Me.Opportunities.SelectedItem.OppStage.OppStageID = 4

    It says that OppStageID is read only.

    OppStageID is an FK to another table that is used to populate a drop down list on the screen.

    Why can I set the other value "Me.Opportunities.SelectedItem.Probablity = 100" but not the OppStageID value?

    Thanks for any help


    Dave Barker


    Thursday, August 1, 2013 2:24 AM

Answers

  • You will want to set Me.Opportunities.SelectedItem.OppStage to an actual entity rather than trying to set the Id.

    So, set ...SelectedItem.OppStage =

     this.DataWorkspace.ApplicationData.OppStage_SingleOrDefault(4);


    paul van bladel

    • Marked as answer by DaveBarker19 Thursday, August 1, 2013 11:49 AM
    Thursday, August 1, 2013 6:16 AM

All replies

  • You will want to set Me.Opportunities.SelectedItem.OppStage to an actual entity rather than trying to set the Id.

    So, set ...SelectedItem.OppStage =

     this.DataWorkspace.ApplicationData.OppStage_SingleOrDefault(4);


    paul van bladel

    • Marked as answer by DaveBarker19 Thursday, August 1, 2013 11:49 AM
    Thursday, August 1, 2013 6:16 AM
  • Thanks Paul that works perfect of course.

    Dave Barker

    Thursday, August 1, 2013 11:49 AM
  • Pleasure to help Dave.

    paul van bladel

    Thursday, August 1, 2013 4:15 PM