Consultor Eletrônico



Kbase P100492: How to update a record in a MS Access table using ActiveX Automation
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   27/01/2005
Status: Unverified

GOAL:

How to update a record in a MS Access table using ActiveX Automation

GOAL:

How to open a MS Access table from Progress using COM Object

FIX:

The following code allows to update the first record of a table called "test" in a MS Access database.

For further information about the MS Access COM object, open the file "MSACC9.olb" (for MS Access 2000) from the COM Object Viewer (Pro*Tools).

The update is done through a DAO Recordset. The list of methods/properties can be checked by opening the file dao360.dll (for DAO 3.60) located in "C:\Program Files\Common Files\Microsoft Shared\DAO".


DEFINE VARIABLE stDBPath AS CHARACTER NO-UNDO.
DEFINE VARIABLE chAccess AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE chRs AS COM-HANDLE NO-UNDO.
/* Initialize string to database path */
stDBPath = "C:\work\access\Northwind.mdb".
/* Create instance of Microsoft Access */
CREATE "Access.Application" chAccess.
/* Open database in Microsoft Access window */
chAccess:OpenCurrentDatabase(stDBPath,TRUE).
/* Open the table "TEST" in a recordset */
chRs = chAccess:CurrentDB:OpenRecordset("test").
/* Go to the first record of the table Test" */
chRs:MoveFirst().
/* Update record*/
chRs:Edit().
chRs:FIELDS("Name") = "test".
chRs:UPDATE(1, FALSE).
/* Display the new value of the field "Name" */
MESSAGE chRs:FIELDS("Name"):VALUE VIEW-AS ALERT-BOX INFO BUTTONS OK.
/* Close the recordset */
chRs:CLOSE().
/* Close the database */
chAccess:closeCurrentDatabase().

/* Exit MS Access */
chAccess:QUIT(0).
/* Release COM-HANDLE */
RELEASE OBJECT ChRs.
RELEASE OBJECT chAccess.