LoginSignup
4
4

More than 5 years have passed since last update.

AccessVBAでADOを使用しテーブルからデータを取得する

Posted at

概要

AccessVBAでADOを使う

説明

ADOでは、コネクション(DB)とレコードセット(SQL)を使用する。

コネクション ( ADODB.Connection )

接続するデータベースを設定する

レコードセット ( ADODB.RecortSet )

SQLを実行し、データを取得する

サンプル

SQLを実行し出力結果を表示する

Sub sample()
    Dim rs As New ADODB.Recordset

    ' SQLを作成
    rs.Open "select * from table", CurrentProject.Connection

    With rs
        Do Until .EOF
            Debug.Print "------"
            For i = 0 To .Fields.Count - 1
                Debug.Print .Fields(i).Name & ": " & .Fields(i).Value
            Next
            .MoveNext
        Loop
    End With

    ' 終了処理
    rs.Close

End Sub
4
4
0

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
4
4