Mega Code Archive

 
Categories / VisualBasic Script / Access
 

Accessing Data with the Fields Collection and Field Objects

Sub field()     Dim dbNorthwind As DAO.Database     Dim dbPath As String     DbPath = CurrentProject.Path & "\mydb.mdb"     Set dbNorthwind = OpenDatabase(dbPath)          Dim rsEmployees As DAO.Recordset     Dim rsCustomers As DAO.Recordset     Set rsEmployees = dbNorthwind.OpenRecordset("Employees", dbOpenTable)     Set rsCustomers = dbNorthwind.OpenRecordset("Customers", dbOpenTable)     I = 2     With rsEmployees         If Not .BOF Then .MoveFirst         Do While Not .EOF             Cells(I, 1).Value = .Fields(2)  'First name in third column             Cells(I, 2).Value = .Fields(1)  'Last name in second column             .MoveNext             I = I + 1         Loop     End With End Sub