Grids display multiple lines of data. Each line in a grid corresponds to one record in a Microsoft Dynamics GP table. Conversely, a Microsoft Dynamics GP window displays only a single record at a time. Since the functionality provided by a window is quite different from that provided by a grid, VBA references a window and a grid that appears in it as separate objects.
It’s also important to note that Microsoft Dynamics GP grids do not function like traditional grids in VBA. You can reference fields on only the current line in a Microsoft Dynamics GP grid, and grid events occur only for the current line. VBA grids typically allow you to work with specified rows and cells within the grid.
When you expand a grid, each line displays two or more rows of data for each record. You expand and shrink a grid using the expand and shrink buttons.
When you add a window containing a grid to your project, VBA adds both the window and the grid. Although the two work together to display information in the accounting system, they are independent objects in your VBA project.
To add a grid object to your project, switch to Microsoft Dynamics GP and display the window containing the grid you want to add. On the Tools menu, point to Customize, then choose Add Current Window To Visual Basic. This will automatically add the currently active (topmost) window and the window’s grid to your project.
When you switch back to Visual Basic, the Project Explorer will display both the grid and window object.
To remove a grid object from your project, switch to Microsoft Dynamics GP and display the window containing the grid you want to remove. On the Tools menu, point to Customize, then choose Remove Current Window From Visual Basic. VBA will remove the window and grid object, as well as any window field objects associated with the window and grid objects.
Be sure you remove all references to a grid after you’ve removed it from the project.
Fields that appear within a grid use the same properties, methods and events as fields that appear in a window. The only difference is that the VBA references the grid’s fields within the context of the grid, and references the window’s fields within the context of the window.
To add a grid’s fields to your project, switch to Microsoft Dynamics GP and display the window containing the grid.
Click the Expand button if you want to add fields from a line when it’s expanded. The expanded line will show two or more rows, each containing multiple fields.
Be sure to select a line in the grid. On the Tools menu, point to Customize, then choose Add Field To Visual Basic. This will activate field selection mode, and a selection pointer will appear.
Using the mouse, click on the fields you’ll use in your project. You only need to add fields from one line to your project. References you make to the field in your VBA project will be for the line currently focused by the user, so it’s not necessary to add the same field from multiple lines in the grid. When you’ve finished adding fields, point to Customize on the Tools menu and choose Add Fields to Visual Basic to deactivate field selection mode.
Field selection mode also deactivates when you switch to the Visual Basic Editor.