Guys,
Few weeks ago I have posted a method to call GP lookup using VBA, but I have noticed that the account lookup form did not show data, so I looked into GP SDK and applied the account lookup calling through ExecuteSanScript function as shown below:
Dim GPApp As New Dynamics.Application
Dim ErrMsg As String
GPApp.CurrentProductID = 1493
Dim strCommand As String
strCommand = " local GLCOA_AccountLookupInfo LookupInfo."
strCommand = strCommand + " set 'LookupInfo:Series' to FINANCIAL. {Series}" + vbNewLine
strCommand = strCommand + " set 'LookupInfo:Sort By' to 4. {Sort By Account Number}" + vbNewLine
strCommand = strCommand + " set 'LookupInfo:Post_Acct' to POST_ACCT.{Show Posting Account}" + vbNewLine
strCommand = strCommand + " set 'LookupInfo:Post_Alloc_Acct' to POST_ALLOC_ACCT." + vbNewLine
strCommand = strCommand + " {-- Show Posting alloc Acct --}" + vbNewLine
strCommand = strCommand + " set 'LookupInfo:Active' to false. {No inactive accounts}" + vbNewLine
strCommand = strCommand + " set 'LookupInfo:Return Alias' to false. {-- Don't return Alias --}" + vbNewLine
strCommand = strCommand + " call Open of form Account_Lookup," + vbNewLine
strCommand = strCommand + " LookupInfo, 'Account Number CS' of window 'GL_Account_Maintenance' of form 'GL_Account_Maintenance', 'Account Number CS' of window 'GL_Account_Maintenance' of form 'GL_Account_Maintenance'." + vbNewLine
GPApp.ExecuteSanscript strCommand, ErrMsg
Now to get this lookup customized to your form and return the data to your field, there are two parameters need to be changed as explained below:
The primary function that will call the lookup is "call Open of form Account_Lookup" the function requires two parameters:
call Open of form Account_Lookup, "Initial Value", "Field to set the returned value in".
1. "Initial Value": this is the value that will be passed to the lookup to initiate the search, by default you might need to use your customized field instead.
2. "Field to set the returned value in": here you need to identify the field that the lookup will return the value in.
So basically replace "'Account Number CS' of window 'GL_Account_Maintenance' of form 'GL_Account_Maintenance'" with your field name and place code above in your Lookup button and the form will show up and works!
Hope that this helps.
Regards,
--
Mohammad R. Daoud
MVP, MCP, MCT, MCBMSP, MCTS, MCBMSS
CTO
+962 - 79 - 999 65 85
Dynamics Innovations
daoudm@dynamicsinnovations.com
http://www.dynamicsinnovations.com
No comments:
Post a Comment