Domino Code Fragment

Code Name*
Simple Test for Writing to an ODBC Data Source Using LotusScript
Date*
04/29/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.18.118.164.151
Description*
The following test script will evaluate whether you can write to an ODBC source using
LotusScript.
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
The script, when executed from a button, will create a new record in a specified ODBC data
source, attempt to save the new record and display a message indicating whether the operation was
completed successfully. If the operation is not completed sucessfully, it is likely that

either your data source is read-only or your ODBC driver does not permit updates to the data
source.

Important: Complete each of the four steps below before running the script.

1. Create a new agent and add the following UseLSX command to the Options event:

UseLSX "*LSXODBC"

2. Add the following script to the Initialize event of the agent. NOTE: Do not add the 'Sub'
and 'End Sub' lines.

Sub Click(Source As Button)
Dim con As New ODBCConnection
Dim qry As New ODBCQuery
Dim res As New ODBCResultSet


If Con.ConnectTo("Addresses")Then
Set Qry.Connection = Con
Qry.SQL = "select * from ADDRESS"
Set Res.Query = Qry
Res.Execute


status = res.AddRow
status = res.SetValue(1,"Testing")
status = res.UpdateRow
If status = True Then
Messagebox "The new record has been created"
Else
Messagebox "Could not create record -- The driver " _
& "or data source may be read only."
End If


res.Close(DB_Close)
con.DisConnect
Else
Messagebox ("Could not connect to data source")
End If
End Sub


3. Replace the "Addresses" data source with the name of any data source registered in your
ODBC control panel.

4. Replace the "ADDRESS" table name with a valid table name contained in the specified data
source.


Supporting Information:
In order to access external databases through ODBC using LotusScript, you must include the
following statement in the (Options) event of the (Global) object.


UseLSX "*LSXODBC"


The following is an excerpt from the Notes R4 on-line help.

Accessing external databases through ODBC using LotusScript

The ODBCConnection, ODBCQuery, and ODBCResultSet classes provide properties and
methods for accessing external databases through the ODBC (Open Database Connectivity)
standard.


You must put the following statement in the (Options) event of the (Global) object to access
the OBDC classes:

UseLSX "*LSXODBC"

You can handle ODBC errors with On Error the same as for Notes methods. In addition, the
ODBC methods return a Boolean status code to indicate success or failure, unless there is

another return, and provide methods GetError, GetErrorMessage, and GetExtendedErrorMessage
to access the last error that occurred.

Include the file LSXODBC.LSS to use the ODBC error names and other constants.