Developing for Dynamics GP

by David Musgrave (Perth, WA, Australia) and the Microsoft Dynamics GP Developer Support Team (Fargo, ND, USA)

Quick Tip: Using fields named as reserved words with Visual Basic for Applications

Quick Tip: Using fields named as reserved words with Visual Basic for Applications

  • Comments 1

David Meego - Click for blog homepageI had a case today that raised an issue that I have seen before which has a simple solution.

The Problem

In summary, when you add a field to Visual Basic from Microsoft Dynamics GP, the name of the field is set to the text in the the linked prompt for that field (or the caption text for buttons). If there is no linked prompt, the name of the field is set to the name of the Dexterity field (with any spaces removed). There is a problem when that field name is the same as a Visual Basic for Application (VBA) keyword or reserved word.

A couple of really common examples are the Date field and the Print button, where Date and Print are reserved words in VBA. When you attempt to use those fields, they are interpreted as the reserved word command and not a field name. Unlike SQL Server which can surround the field with [square brackets], there is no method to force VBA to use the keyword as a field.

I did some background research and did find a couple of Knowledge Base (KB) articles which refer to the same issue. 

 

The Solution

To demonstrate the issue and the solution, here are a series of screenshots.

  • On the Sales Transaction Entry window, I want to add the Dexterity 'Document Date' field to Visual Basic. I have already Added the Current window to Visual Basic, so now I select Add Fields to Visual Basic ...

  • I then click on the Date field (highlighted below). Note: The prompt text is "Date".

  • Once I select to go to the Visual Basic Editor and click on the SalesTransactionEntry module under the Microsoft_Dynamics_GP project, I can select the Date field from the drop down list to see its properties. Note: The only property available is the Name.

  • Once I edit the Name property so that it is no longer a reserved word, for example: DocumentDate, the rest of the window field's properties are available. 

After changing a field name, just make sure that any code written now references the updated name for the field and everything will work as expected.

Hope this helps. 

David

Page 1 of 1 (1 items)
Comments Information

PLEASE READ BEFORE POSTING

Please only post comments relating to the topic of this page.

If you wish to ask a technical question, please use the links in the links section (scroll down, on right hand side) to ask on the Newsgroups or Forums. If you ask on the Newsgroups or Forums, others in the community can respond and the answers are available for everyone in the future.

Leave a Comment
  • Please add 3 and 8 and type the answer here:
  • Post