Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics SL (Archived)

Adding field from another table to grid in SL 7.0

Posted on by 95

I am trying to add a field from the purorddet table to the Sales Order Entry screen (40.100.00).  The field is used to store a tracking number for Sales Orders that generate a Purchase Order.  I have added the Purorddet table to the screen using a VBASetAddr call, and have declared a cursor on the PurOrdDet table using SQLCursorEx.  I have written a stored procedure that returns the Purorddet record when supplied with a Sales Order number and Lineref value. Finally, I have added the field from purorddet to the Sales Order Entry screen, in the grid.

When I put code in the check event for the Order Number, the code fires and the Tracking number populates on the first line item for the order.  However, all subsequent lines show the same tracking number as the first line.

I know I likely have to loop through the lines in the grid and execute the stored procedure for each line, but I am not sure how to do that in VBA.  Any help would be very much appreciated.

 

John

*This post is locked for comments

  • John Kowalke Profile Picture
    John Kowalke 95 on at
    Re: Adding field from another table to grid in SL 7.0

    Yep, the Dispfields statement in LineGotFocus worked.  Thanks again for all your help.

  • Barry Flynn Profile Picture
    Barry Flynn 3,090 on at
    Re: Adding field from another table to grid in SL 7.0

    John

    As a wild (and probably silly) guess, you might consider putting a DispField of your field in LineGotFocus.

    But that is probably a silly suggestion, because, to my knowledge, you shouldn't need to do anything.

    Form View should "just work".

    Barry

  • John Kowalke Profile Picture
    John Kowalke 95 on at
    Re: Adding field from another table to grid in SL 7.0

    One additional question, if anyone has an answer.  My grid now shows the field properly for each line in grid view, but when I select a line and switch to form view, the field only shows the value for the first line, no matter which line is selected.  Do I need to put code in the LineGotFocus event for the grid to update the field when a line is selected?

    Thanks,

    John

  • John Kowalke Profile Picture
    John Kowalke 95 on at
    Re: Adding field from another table to grid in SL 7.0

    Barry - you are awesome.  That was exactly what I needed, to see an example.  Thanks very very much!

    John

  • Verified answer
    Barry Flynn Profile Picture
    Barry Flynn 3,090 on at
    Re: Adding field from another table to grid in SL 7.0

    John

    One thing you may have missed is putting a VBA_Mextend call in Form Display.

    That "adds your buffer" to the grid.

    Without that call, there is just one instance of your buffer, holding a single value.

    When you do that call, there are multiple instances of your buffer - one per grid line.

    You are right in saying that you need to execute the proc for each line.

    The code may (or may not) look a little bit like this

       liRowNum = MGetRowNum(garrFAHandle)

       liGridFetch = MFirst(garrFAHandle, liMaintFlg)

       Do While liGridFetch = 0

               --- run your proc & populate your buffer

               Call MUpdate(garrFAHandle)

           liGridFetch = MNext(garrFAHandle, liMaintFlg)

       Loop

       ' point the grid back where it was before we started

       Call msetrownum(garrFAHandle, liRowNum)

       Call MDisplay(garrFAHandle)

    Hope that helps a bit

    Barry

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans