0
0

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 1 year has passed since last update.

レコードの存在チェック

Last updated at Posted at 2024-03-27
Public Sub CheckRecordExistence()
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim sql As String
    
    ' SQLクエリを準備します。ここではEmployeeIDが1のレコードを検索しています。
    sql = "SELECT * FROM Employees WHERE EmployeeID = 1"
    
    ' 現在のデータベースを開きます。
    Set db = CurrentDb()
    
    ' SQLクエリを実行し、結果をRecordsetオブジェクトに格納します。
    Set rs = db.OpenRecordset(sql, dbOpenDynaset)
    
    ' レコードが存在するかどうかをチェックします。
    If rs.EOF And rs.BOF Then
        MsgBox "対象のレコードは存在しません。", vbInformation, "レコードなし"
    Else
        MsgBox "対象のレコードが見つかりました。", vbInformation, "レコードあり"
    End If
    
    ' オブジェクトを閉じてリソースを解放します。
    rs.Close
    Set rs = Nothing
    Set db = Nothing
End Sub
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?