Berikut ini adalah cara mengetahui daftar nama field di suatu tabel database MS Access di visual basic 6, untuk mempraktekannya siapkan :
1. Buat 1 Project baru dengan 1 Form, 1 ListBox, dan 1 Commandbutton.2. Tambahkan reference Microsoft DAO 3.51 Object Library.
3. Copy-kan coding berikut ke editor form yang bertalian.
Public Function FieldNames(dbPath As String, TableName As _
String) As Collection
'Input:
'dbPath: Path lengkap file database MS Access
'TableName: Nama tabel di dalam database
Dim oCol As Collection
Dim db As DAO.Database
Dim oTD As DAO.TableDef
Dim lCount As Long, lCtr As Long
Dim f As DAO.Field
On Error GoTo errorhandler
Set db = Workspaces(0).OpenDatabase(dbPath)
Set oTD = db.TableDefs(TableName)
Set oCol = New Collection
With oTD
lCount = .Fields.Count
For lCtr = 0 To lCount - 1
oCol.Add .Fields(lCtr).Name
List1.AddItem .Fields(lCtr).Name
Next
End With
MsgBox FieldNames
db.Close
Set FieldNames = oCol
Exit Function
errorhandler:
On Error Resume Next
If Not db Is Nothing Then db.Close
Set FieldNames = Nothing
Exit Function
End Function
Private Sub Command1_Click()
Call FieldNames(App.Path & "\Akademik.mdb", "Mahasiswa")
End Sub
Tags:
contoh program vb6, contoh fungsi di vb6, cara penggunaan fungsi vb, tutorial vb6, download tutorial vb6, vb6 tutorial download, dasar dasar vb6, belajar vb6, cara mudah belajar vb6, vb6 artikel download, vb6 blog, contoh program vb6, artikel vb6, semua tentang vb6, vb6 api, cara menggunakan module, cara menggunakan class module
0 komentar:
Posting Komentar