Jetデータベースのテーブル名を列挙し、コンボボックス、リストボックスにその名称を追加します。
Private SubForm_Load()
Call TblNameCtlSet(Combo1, App.Path & "\work.mdb")
Call TblNameCtlSet(List1, App.Path & "\work.mdb")
End Sub
SubTblNameCtlSet(ctlControlAs Control, strDbPathAs String)
Dim wsAsWorkspace
Dim dbAsDatabase
Dim tdfAsTableDef
If TypeOfctlControlIsComboBoxOrTypeOf ctlControlIsListBoxThen
Else
Exit Sub
End If
ctlControl.Clear
Set ws= DBEngine.Workspaces(0)
Set db= ws.OpenDatabase(strDbPath, False, True)
ctlControl.Clear
'テーブル名をコントロールに追加
For Each tdfIndb.TableDefs
If(tdf.AttributesAnddbSystemObject) = 0Then
ctlControl.AddItem tdf.Name
End If
Next
If TypeOf ctlControlIsComboBoxThen
ctlControl.Text = ctlControl.List(0)
End If
db.Close
ws.Close
End Sub
DownLoad vbtips023.lzh 7KB (VB6.0)