0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Access VBA TIPS

Last updated at Posted at 2021-05-26

フィールド名を一括変更する

hoge.txt
Public Sub FieldNameChange()

  Dim dbs As DAO.Database

  Set dbs = CurrentDb

  'ここでテーブル名を指定します
  With dbs.TableDefs("tblデータ1")
    '現在のフィールド名(左辺)と新しい名前(右辺)を列挙します。
    .Fields("フィールド1").Name = "ID"
    .Fields("フィールド2").Name = "社員番号"
    .Fields("フィールド3").Name = "名前"
    .Fields("フィールド4").Name = "ふりがな"
    .Fields("フィールド5").Name = "生年月日"
    .Fields.Refresh
  End With

End Sub

フィールド名を一括取得する

hoge.txt

Public Sub GetFieldNameSample()
    Dim myDB As DAO.Database
    Dim myTD As TableDef
    Dim myFild As Field
    'カレントデータベースを変数に代入する
    Set myDB = CurrentDb
    'フィールドを表示するテーブルを変数に代入する
    Set myTD = myDB.TableDefs!社員テーブル
    '[社員テーブル]のフィールドを表示する
    For Each myField In myTD.Fields
        Debug.Print myField.Name
    Next
End Sub

Selectした結果をINSERTする

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?