Visual Basic Tips


Jetデータベース(DAO)クエリー名の列挙


Jetデータベースのクエリーを列挙し、コンボボックス、リストボックスにその名称を追加します。

Private Sub Form_Load()
  Call QeyNameCtlSet(Combo1, App.Path & "\work.mdb")
  Call QeyNameCtlSet(List1, App.Path & "\work.mdb")
End Sub

Sub QeyNameCtlSet(ctlControl As Control, strDbPath As String)
  
Dim ws As Workspace
  
Dim db As Database
  
Dim qdf As QueryDef

  
If TypeOf ctlControl Is ComboBox Or TypeOf ctlControl Is ListBox Then
  
Else
    
Exit Sub
  
End If

  ctlControl.Clear

  
Set ws = DBEngine.Workspaces(0)
  
Set db = ws.OpenDatabase(strDbPath, False, True)

  
'クエリー名を追加
  
For Each qdf In db.QueryDefs
    ctlControl.AddItem qdf.Name
  
Next

  
If TypeOf ctlControl Is ComboBox Then
    ctlControl.Text = ctlControl.List(0)
  
End If

  db.Close
  ws.Close
End Sub


DownLoad vbtips025.lzh 7KB (VB6.0)