Handling Translation when Customizing with VBA

David MeegoFrom the Translating Dexterity Applications Series

The final topic in the series is one that was added later after I was asked about how to handle translated applications when writing customizations.

Most code would work fine as it is independent of the language. However, it is common in Visual Basic for Applications (VBA) customizations to read the prompt from a dialog using the Window_AfterModalDialog() event and take action based on the prompt text.  On a translated system this text will differ.

The solution is that you would need to look for the prompt in each language.  You can use a select case statement as shown in the US English versus International English example below:

VBA Code Example

 Private Sub Window_AfterModalDialog(ByVal DlgType As DialogType, PromptString As String, Control1String As String, Control2String As String, Control3String As String, Answer As DialogCtrl)
    Select Case PromptString
        Case "Are you sure you want to delete this Customer ID?"

        Case "Are you sure you want to delete this Debtor ID?"
        
        Case Else
     End Select
End Sub

The easiest method of capturing the exact text to use is by placing a breakpoint at the beginning of the select case statement. Then once the code is paused, use the immediate window to type "? PromptString" and then press Enter.  You can the cut and paste the prompt into the code.

Advanced Method: If you want to try a more advanced method, it would be possible to get the message resource (if you know the Message ID) from Dexterity using passthrough sanScript and returning the result to the SY_User_Object_Store (SY90000) DUOS table and then reading the DUOS from VBA. This example demonstrates the techniques involved: Hybrid - Changing Screen Colours Depending on Company Example. Comparing against the message from Dexterity itself will always work regardless of language.

This is a good method of having a single set of code that will work for all languages. However, it is likely that each language is going to have its own application folder and so you can have separate code for each language as well.

Have fun customizing.

David