WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with Access

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Get Column Data From an Access Database

 Keywords: Column Data Access Database .MDB 

Question:

How can I read data from a cell in a specific column in a Access Database *.mdb?

Answer:

The following code, should get you started. Simply specify a valid .mdb file, table name, and column name, to get a list of all values in that column.
mdb = "C:\Temp\Data files\test.mdb" 
tablename = "Contacts"
columnname = "ID"
query = StrCat("select ",columnname," from ",tablename)

; create the access application object
objApp = objectopen("Access.Application")
; open the database
objApp.opencurrentdatabase(mdb)
; get the current database object
objCurrentdb = objApp.currentdb
; open the recordset
objRecordset = objCurrentdb.openrecordset(query)
; get the fields collection
objfields = objRecordset.fields
; loop through the recordset
while objRecordset.eof == @false
   fieldcount = objfields.count
	For x = 0 to fieldcount-1
	   objfield = objfields.Item(x)
      message(objfield.name, objfield.value)
	Next
	objRecordset.movenext
endwhile
objRecordset.close
objApp.closecurrentdatabase
objApp.quit

; close up the objects...
objectclose(objfield)
objectclose(objfields)
objectclose(objRecordset)
objectclose(objCurrentdb)
objectclose(objApp)

message("", "Done")
exit


Article ID:   W15618
File Created: 2003:05:13:11:29:16
Last Updated: 2003:05:13:11:29:16