Code Samples for Businesses, Schools & Developers

First Published 29 Jan 2023             Last Updated 8 Sept 2024

The unicode input box was developed for use with my Access Application Translator utility which is due for release during February 2023

I created it because the standard input box only works with Latin script languages such as English, German, Spanish etc.
It cannot handle languages which use Unicode character sets such as Arabic or Bengali unless additional changes are made to locale and keyboard settings

English

StandardInputBoxEn
French

StandardMsgBoxFr
Bengali

StandardInputBoxBn

By contrast, the unicode input box has been designed to handle text in languages that use Unicode character sets such as Japanese, Greek, Bengali etc without needing to change locale or keyboard settings. This includes right-to left languages such as Arabic and Hebrew.

English

UnicodeInputBoxEn
Arabic

UnicodeInputBoxAr
Korean

UnicodeInputBoxKo

NOTE: The button positions cannot be altered on either type of input box


The unicode input box uses similar code to that of the Formatted Message Box function

In both cases, the Eval function is used to achieve the desired outcome
However, in this case it does NOT cause the first line of text to become bold

CODE:

Public Function UnicodeInputBox(Prompt As String, Optional Title As String = vbNullString, _
      Optional Default As String = vbNullString, Optional Xpos As Variant, Optional Ypos As Variant) As String

'---------------------------------------------------------------------------------------
' Function       : UnicodeInputBox

' DateTime       : 25/01/2023
' Author            : Colin Riddington (Mendip Data Systems)
' Website          : https://www.isladogs.co.uk
' Purpose          : Input box that works with unicode character set languages such as Arabic/Greek

' Copyright       : The code in the utility MAY be altered and reused in your own applications
'                             provided the copyright notice is left unchanged (including Author, Website and Copyright)

'                             You are NOT allowed to sell, resell or repost this on other sites such as online forums
'                             without permission from the author. However, links back to the above websites ARE allowed.

'                             If you find this code useful please place a link to my website on your own web site
'                             so that others may benefit as well.

' Updated       : January 2023

'---------------------------------------------------------------------------------------

On Error GoTo Err_Handler

      'Also works with unicode character sets
      If IsMissing(Xpos) And IsMissing(Ypos) Then
            'position not specified - place in centre of screen
            UnicodeInputBox = Eval("InputBox(""" & Prompt & """, " & _
                  " """ & Title & """, """ & Default & """)")
      Else
            'position left at XPos, top at YPos
            UnicodeInputBox = Eval("InputBox(""" & Prompt & """, " & _
                  " """ & Title & """, """ & Default & """, " & Xpos & ", " & Ypos & ")")
      End If

Exit_Handler:
      Exit Function

Err_Handler:
      MsgBox "Error " & Err.Number & " in UnicodeInputBox procedure : " & vbNewLine & " - " & Err.Description
      Resume Exit_Handler

End Function


For example:

a)   Simple input box with a prompt and title only. It will be centred on the screen

UnicodeInputBox "Enter a language ID between 1 and 109", "Enter Language ID"


UIBExample1
b)   Input box in Italian with a prompt, title and default text. Screen position : left = 3000 twips and top = 5000 twips from top left corner

UnicodeInputBox "Seleziona un colore da questo elenco" & vbCrLf & "Rosso, blu, verde, giallo", _
      "Scegli un colore", "Inserisci un colore", 3000, 5000


UIBExample2
c)   Input box translated into Malayalam and centred on screen

UnicodeInputBox TranslateXL("Enter a Record ID between 1 and 27", "en", "ml"), _
      TranslateXL("Select Record ID", "en", "ml"), TranslateXL("Record Number", "en", "ml")


UIBExample3

NOTE:
1.   The language used for the OK / Cancel buttons is updated automatically when the default Office language is changed

2.   Clicking the "?" in the title bar opens a Microsoft help article for Access 365: Top categories
      At the time of writing this article, I have been unable to find a way of removing or changing this link

3.   As with standard input boxes, functions can also be included in the input box text.

      In this example, it is being used with a function GetDefaultLanguage:

UnicodeInputBox "The current default language is " & GetDefaultLanguage() & vbCrlf & vbCrLf & _
      "Enter the new default language (or click Cancel)" & vbCrLf, "Change Default Language?"


UIBExample4


4.   If you want to use the Unicode input box as your default input box, just rename the function as InputBox. It will then replace the VBA InputBox function



UPDATE: 8 Sept 2024
A question about standard input boxes and large monitors recently came up in a thread at Access World Forums: Overflow error on input box

In a standard input box, the x-pos and y-pos variables are both integers so give an overflow error if either is set to be greater than the integer limit of 32767.
However, in the unicode input box, the x-pos & y-pos variables are variants (or you can substitute Long for each).

The result is it can be successfully used with larger values typically needed with large monitors (or with multiple monitors). For example:

UnicodeInputBox "Large Monitor Test", "Form2", "This works on large monitors", 51000, 10000


LargeMonitorTest


Feedback

Please use the contact form below to let me know whether you found this article interesting/useful or if you have any questions/comments.

Please also consider making a donation towards the costs of maintaining this website. Thank you



Colin Riddington             Mendip Data Systems            Last Updated 8 Sept 2024



Return to Code Samples Page




Return to Top