Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics SL (Archived)

Adding field from another table to grid in SL 7.0

(0) ShareShare
ReportReport
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
    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
    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
    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
    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
    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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,060 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,858 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans