• 解説

    AccessでコンボボックスのIME入力モードを使用不可にしている場合でも、勝手に有効になってしまうバグは有名です。
    ちょっと2007を使う機会があったので直っているかと思い、やってみると直っていない、Microsoftは直す気ないのかね。

    仕方がないのでAPIを使って制御することにします。(ある程度汎用的に作ってあります)

  • サンプル

    標準モジュール

    Option Compare Database
    Option Explicit
    
        Private Const IME_CMODE_ALPHANUMERIC            As Long = &H0
        Private Const IME_CMODE_NATIVE                  As Long = &H1
        Private Const IME_CMODE_CHINESE                 As Long = IME_CMODE_NATIVE
        Private Const IME_CMODE_HANGEUL                 As Long = IME_CMODE_NATIVE
        Private Const IME_CMODE_HANGUL                  As Long = IME_CMODE_NATIVE
        Private Const IME_CMODE_JAPANESE                As Long = IME_CMODE_NATIVE
        Private Const IME_CMODE_KATAKANA                As Long = &H2
        Private Const IME_CMODE_LANGUAGE                As Long = &H3
        Private Const IME_CMODE_FULLSHAPE               As Long = &H8
        Private Const IME_CMODE_ROMAN                   As Long = &H10
        Private Const IME_CMODE_CHARCODE                As Long = &H20
        Private Const IME_CMODE_HANJACONVERT            As Long = &H40
        Private Const IME_CMODE_SOFTKBD                 As Long = &H80
        Private Const IME_CMODE_NOCONVERSION            As Long = &H100
        Private Const IME_CMODE_EUDC                    As Long = &H200
        Private Const IME_CMODE_SYMBOL                  As Long = &H400
        Private Const IME_CMODE_FIXED                   As Long = &H800
        Private Const IME_CMODE_RESERVED                As Long = &HF0000000
    
        Private Const IME_SMODE_AUTOMATIC               As Long = &H4
    
        Public Enum IME_MODE
            IME_NONE = 0                     'なし
            IME_HIRAGANA = 1                 '全角ひらがな
            IME_KATAKANA = 2                 '全角カタカナ
            IME_WIDE = 3                     '全角英数
        End Enum
    
        Private Declare Function GetFocus Lib "user32.dll" () As Long
        Private Declare Function ImmGetContext Lib "Imm32.dll" _
                       (ByVal hWnd As Long) As Long
        Private Declare Function ImmReleaseContext Lib "Imm32.dll" _
                       (ByVal hWnd As Long, _
                        ByVal hIMC As Long) As Long
        Private Declare Function ImmSetConversionStatus Lib "Imm32.dll" _
                       (ByVal hIMC As Long, _
                        ByVal fdwConversion As Long, _
                        ByVal fdwSentence As Long) As Long
        Private Declare Function ImmSetOpenStatus Lib "Imm32.dll" _
                       (ByVal hIMC As Long, _
                        ByVal fOpen As Integer) As Long
    
    Public Function SetIMEMode(ByVal Mode As IME_MODE) As Boolean
    
        Dim WindowHandle                                As Long
        Dim InputMethodManagerHandle                    As Long
        Dim Conversion                                  As Long
    
        SetIMEMode = False
    
        WindowHandle = GetFocus()
    
        If WindowHandle = 0 Then
            Exit Function
        End If
    
        InputMethodManagerHandle = ImmGetContext(WindowHandle)
    
        If Mode <> 0 Then
            ImmSetOpenStatus InputMethodManagerHandle, True
    
            Select Case Mode
                Case IME_HIRAGANA
                    Conversion = IME_CMODE_NATIVE Or _
                                 IME_CMODE_FULLSHAPE
                Case IME_KATAKANA
                    Conversion = IME_CMODE_NATIVE Or _
                                 IME_CMODE_KATAKANA Or _
                                 IME_CMODE_FULLSHAPE
                Case IME_WIDE
                    Conversion = IME_CMODE_FULLSHAPE
            End Select
    
            ImmSetConversionStatus InputMethodManagerHandle, _
                                   Conversion, _
                                   IME_SMODE_AUTOMATIC
        Else
            ImmSetOpenStatus InputMethodManagerHandle, False
        End If
    
        ImmReleaseContext WindowHandle, InputMethodManagerHandle
    
        SetIMEMode = True
    
    End Function
    

    使用方法は

        SetIMEMode IME_NONE
    

    と、なります。

  • その他

    97はType Enumが使えないのでConst宣言する必要があります。
    AccessのVBAおよびAPIの知識が必要です。

説明がわからないなどありましたらお問い合わせでお知らせください。

ここに掲載された情報を使用したことによって発生した、いかなる損害に対しても
管理者である雅は一切責任を負いません。