Message Image  

Open Forum

VBA Customization - Project Terms Default on Invoices - Question / Issue

  • 1.  VBA Customization - Project Terms Default on Invoices - Question / Issue

    BRONZE CONTRIBUTOR
    Posted 04-13-2018 01:48 PM
    Edited by Justin Fishwick 04-13-2018 01:50 PM

    Hi Folks - semi cross-post, but looking for some possible input on adding some VBA to change the field default in an screen in SL.

    - Objective: Populate default terms from our Contract Maintenance maintained terms field rather than from the default (Customer) link
    - Screen: Invoice & Adjustment Maintenance (BI.BAM.00)
    - Field: Terms (pjinvhdr.ih_id18)

    We are able to get the field to pre-populate with our expected result when we load the screen and select an associated project ID, but upon save, it reverts back to the Customer defaults.

    Not sure if this is something regarding the timing of when we try to override the default or if we shouldn't be monkeying with this field default to begin with.

    Sample code we are working with is below. Any input would be helpful!

    Private Sub Form1_Display()
    
    End Sub
    Sub Form1_Load()
        Call SqlCursor(c1, NOLEVEL)
    
    End Sub
    Sub cTerms_Default(newvalue$, retval%)
        Dim strSQLStmt As String
        Dim strTermsID As String
        Dim strProjectID As String
        
        strProjectID = GetObjectValue("cbill_project")
        
        strSQLStmt = ""
        strSQLStmt = "SELECT CASE WHEN c.termsid IS NULL OR c.termsid = '' THEN '00' ELSE c.termsid END AS termsid " & _
                     "FROM pjproj as p LEFT OUTER JOIN pjcont as c on p.contract = c.contract " & _
                     "WHERE p.project = " & SParm(strProjectID)
        'MsgBox strSQLStmt
        
        serr1 = SqlFetch1(c1, strSQLStmt, bContResult, LenB(bContResult))
        
        'SqlFetch returns 0 if records are returned or NOTFOUND if no records are returned
        If serr1 = NOTFOUND Then
            'Call MessBox("Error Locating Project " + SParm(strProjectID), MB_OK, "Can't Assign TermsID")
            Exit Sub
        Else
            'Check to see if the terms field is enabled or not so we don't modify posted records
            If cTerms.Enabled = True Then
                strTermsID = bContResult.termsid
                'Call MessBox("Assign TermsID: " + strTermsID, MB_OK, "Terms to assign")
                'Call SetObjectValue("cTerms", strTermsID)
                
                Call SetBufferValue("bpjinvhdr.ih_id18", strTermsID)
                
            End If
        End If
        
    End Sub


    Many thanks,
    Justin



    ------------------------------
    Justin Fishwick
    Manager of Business Analysis
    The Brattle Group
    ------------------------------


  • 2.  RE: VBA Customization - Project Terms Default on Invoices - Question / Issue

    BRONZE CONTRIBUTOR
    Posted 04-13-2018 04:13 PM
    Did you remove the default setting in the actual control on the screen as well. Your customized vba setting will be overwritten if it is defined in the screen control as well.

    ------------------------------
    Rex Phillips
    TRI-KES
    Dallas TX
    ------------------------------



  • 3.  RE: VBA Customization - Project Terms Default on Invoices - Question / Issue

    BRONZE CONTRIBUTOR
    Posted 04-13-2018 05:18 PM
    Edited by Justin Fishwick 04-13-2018 05:18 PM
    Thanks, Rex. Yes - I failed to mention we cleared the Default in the Properties screen, but I didn't change the PV code. It still likes to jump back to the customer level terms, so I wasn't sure if its something that's triggered past the basic VBA / screen level.

    Put a screenshot of the properties window below for reference:



    ------------------------------
    Justin Fishwick
    Manager of Business Analysis
    The Brattle Group
    ------------------------------