stevennathaniel

MS Access VBA DAO : Sedikit Modifikasi di Pilihan Database

Mar 15th, 2016
133
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Compare Database
  2.  
  3. Public Sub VBADAO3()
  4.  
  5. Dim DAM As String
  6.  
  7. Dim db As DAO.Database
  8.  
  9. Dim rst As DAO.Recordset
  10.  
  11. Dim query As String
  12.  
  13. DAM = "VBA DAO"
  14.  
  15. 'Sumber : https://msdn.microsoft.com/en-us/library/office/ff965871%28v=office.14%29.aspx
  16.  
  17. ' Jalankan pointer ke database yg dipakai sekarang
  18.  
  19. ' Set db = OpenDatabase("D:\fileAccess\Database2.mdb")
  20. Set db = DBEngine.OpenDatabase("D:\fileAccess\Database2.mdb")
  21.  
  22. Debug.Print DAM & ": Successfully connected to database. Data source name: " & vbNewLine & " " & db.Name
  23.  
  24. ' Menyiapkan SQL query
  25.  
  26. query = "SELECT databarang.[namabarang],databarang.[hargabarang]FROM databarang"
  27.  
  28. Debug.Print DAM & ":SQL Query:" & vbNewLine & " " & query
  29.  
  30.  
  31. Set rst = db.OpenRecordset(query)
  32.  
  33. Debug.Print DAM & ": Retrieve schema info for the given result set: "
  34.  
  35. For i = 0 To rst.Fields.Count - 1
  36.  
  37. Debug.Print " | " & rst.Fields(i).Name
  38.  
  39. Next i
  40.  
  41. End Sub
RAW Paste Data