Microsoft ActiveX Data Objects (ADO)

Using OLE DB Object Services with Microsoft ActiveX Data Objects (ADO) is the most powerful and flexible way to use of the connector because it offers you the most control over your applications. However, you must understand ADO and Visual Basic (VB) programming. The examples that show how to use OLE DB Object Services with ADO will assume knowledge of both ADO and VB.

The best way to show how to use the connector with ADO is with a small code example. The following is an application that extracts and prints a list of employees. The portions in bold were generated by the OLE DB connector Query Builder.

Example

This example code works anywhere that Visual Basic for Applications (VBA) is available. (A variation of this code could be used to create a Microsoft Excel macro to extract data from Lawson to a spreadsheet.)

Start a new VB executable project, add a reference to the ADO 2.1 library, and paste the following code, generated through the Form/Load procedure. In this example "XXX" is used for connection string data.

Dim cn As New ADODB.Connection
cn.ConnectionString = "Provider=Lawson.LawOLEDBC;Data Source=XXX;
User ID=XXX;Password=XXX"
cn.Open
Dim rs As New ADODB.Recordset
rs.ActiveConnection = cn
rs.Open "dme:FILE=EMPLOYEE&FIELD=EMPLOYEE;LAST-NAME;FIRST-NAME;EMP-STATUS;EMP-STATUS.DESCRIPTION;EMP-STATUS.PAY-STATUS"
rs.MoveFirst
While rs.EOF <> True
Debug.Print rs.Fields("LAST-NAME").Value
rs.MoveNext
Wend
End

The following are the ADO Data Control properties that you must always verify and set to appropriate values.

Data Control Property Comments
CommandType Set to "adCmdText" for Form or Database command strings. Set to "adCmdTable" for an entire Database table.
ConnectionString

Type the Provider name, data source (Lawson product line), User ID, and password

Example

"Provider=Lawson.LawOLEDBC;Data Source=XXX;User ID=XXX;Password=XXX"

CursorLocation Set to "adUseServer." This makes ADO use the connector directly instead of using the Microsoft-supplied client-side cursor library.
CursorType Set to "adOpenStatic."
LockType

Set to "adLockReadOnly" for read only record sets.

Set to "adLockOptimistic" for read/write record sets.

MaxRows

Set to 0 for all rows unless you want to make Form calls.

When you make Form calls, set this to a number to cap the number of rows.

Mode

Set to "adModeRead" for read only record sets.

Set to "adModeReadWrite" for read/write record sets.

RecordSource

Set to a Form or Database string if CommandType is "adCmdText."

Set to a Database file name (uppercase) if CommandType is "adCmdTable."