SHARE
TWEET

MS Access VBA DAO : Tampil Data & Skema Secara Lengkap

stevennathaniel Mar 14th, 2016 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Compare Database
  2.  
  3. Public Sub VBADAO2()
  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.  
  14. 'Jalankan pointer ke database yg dipakai sekarang
  15.  
  16. Set db = CurrentDb()
  17.  
  18.  
  19.  
  20. 'Menyiapkan SQL query
  21.  
  22. query = "SELECT databarang.[namabarang], databarang.[hargabarang] FROM databarang"
  23.  
  24. Debug.Print DAM & ": SQL Query: " & vbNewLine & " " & query
  25.  
  26.  
  27. ' Run the query and create a record set
  28.  
  29. Set rst = db.OpenRecordset(query)
  30.  
  31.  
  32. Debug.Print DAM & ": Retrive schema info for the given result set: "
  33.  
  34. For i = 0 To rst.Fields.Count - 1
  35.  
  36. Debug.Print " | " & rst.Fields(i).Name
  37.  
  38. Next i
  39.  
  40.  
  41. Debug.Print DAM & ": Fetch the actual data: "
  42.  
  43. Do While Not rst.EOF
  44.  
  45.     Debug.Print " | " & rst![namabarang] & " | " & rst![hargabarang]
  46.    
  47.     rst.MoveNext
  48.    
  49.     Loop
  50.    
  51.    
  52.     Debug.Print DAM & ": Total Row Count: " & rst.RecordCount
  53.    
  54.     Debug.Print DAM & ": Cleanup. Done. "
  55.    
  56.    
  57.     rst.Close
  58.    
  59.     db.Close
  60.  
  61. End Sub
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top