LoginSignup
1
0

More than 3 years have passed since last update.

【Access】コンボボックスの選択されている値を取得【VBA】

Last updated at Posted at 2021-05-18

はじめに

VBAでコンボボックスの値を取得する方法です。
コンボボックスに値を設定してから行ってください。

取得方法

コンボボックス

  • 「テーブル/クエリ」の場合の以下の通りに行ってください。
  • 「値リスト」の場合は2.値を取得はできないので飛ばしてください。

image.png

1.キーを取得
”コンボボックス名”.Value
2.値を取得
”コンボボックス名.”Text

コードサンプル

Private Sub コンボ1_AfterUpdate()    
    '変数宣言
    Dim cmbValue As Variant
    Dim cmbText As Variant

  '値を取得
    cmbValue = コンボ1.Value
    cmbText = コンボ1.Text

    'イミディエイトに出力
    Debug.Print "Valueは" & cmbValue
    Debug.Print "Textは" & cmbText
End Sub

1.選択する
image.png
2.値が出力される
image.png

1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0