AccessDAO - Question 8 |
|
; ; Question 8 -- How do I see which fields are in my table ? ; ; First we setup the variables and open the DAO objects... ; dbname = StrCat(DirScript(), "Winbatch-Access-Tutorial.mdb") dao = ObjectCreate("DAO.DBEngine.36") ws = dao.CreateWorkspace("JetWorkspace", "admin", "") db = ws.OpenDatabase(dbname) ; ; DAO uses a process similar to the previous DAO example but ; since we know which table we want, we can ask for it specifically... ; count = db.tabledefs("Employees").fields.count Message("Fields in Table", count) ; ; Next we loop through the collection of fields and get the ; information about them. The "type" field returns a number which of ; course corresponds to the numbers we used to construct the table in ; the first script... ; TableInfo = "" TableName = "Employees" ; For x = 0 To count-1 fldmsg = "" fldmsg = StrCat(fldmsg, "Name: ", db.tabledefs(TableName).fields(x).name, @LF) fldmsg = StrCat(fldmsg, "Type: ", db.tabledefs(TableName).fields(x).type, @LF) fldmsg = StrCat(fldmsg, "Size: ", db.tabledefs(TableName).fields(x).size, @LF) ; message("Debug", fldmsg) TableInfo = ItemInsert(fldmsg, -1, TableInfo, @LF) Next Message("Table Info", TableInfo) ; ; Obviously if you know the name of the field you want you can reference it just like ; the table, instead of using .fields(x) like .fields("EmployeeID") and DAO or Access ; won't mind if it's numeric or string values. ; ; Zero out the OLE handle... db = 0 ws = 0 dao = 0