This example is a form that contains two text fields named dataSource and Table, two buttons with the same names, and two actions named "List tables" and "List procedures." Notice the use of global declarations so that all the scripts on the form can access the same objects and the data. The form's Postopen script sets the objects, gets the names of the available data sources, writes the first one to the dataSource field, gets the names of the tables for the data source, and writes the first one to the Table field. The "Data source" button writes the name of the next data source to the dataSource field, gets the tables for the new data source, and writes the first one to the Table field. The "Table" button writes the name of the next table to the Table field. The "List fields" action displays the names of all the fields for the current data source and table. The "List procedures" action displays the name of all the procedures for the current data source.Uselsx "*LSXODBC"
(Globals) (Declarations)
Dim con As ODBCConnection
Dim dataSources As Variant
Dim tables As Variant
Dim thisdsn As Integer
Dim thistable As Integer
Dim workspace As NotesUIWorkspace
Dim uidoc As NotesUIDocument
Sub Postopen(Source As Notesuidocument)
Set workspace = New NotesUIWorkspace
Set uidoc = workspace.CurrentDocument
Set con = New ODBCConnection
con.SilentMode = True
dataSources = con.ListDataSources
thisdsn = Lbound(dataSources)
Call uidoc.FieldSetText("dataSource", & _
dataSources(thisdsn))
tables = con.ListTables(dataSources(thisdsn))
If Ubound(tables) <> 0 Then
thistable = Lbound(tables)
Call uidoc.FieldSetText("Table", & _
tables(thistable))
End If
End Sub
Sub Queryclose(Source As Notesuidocument, Continue As Variant)
If con.IsConnected Then
con.Disconnect
End If
End Sub
REM "Data source" button
Sub Click(Source As Button)
If thisdsn = Ubound(dataSources) Then
thisdsn = Lbound(dataSources)
Else
thisdsn = thisdsn + 1
End If
Call uidoc.FieldSetText("dataSource", & _
dataSources(thisdsn))
tables = con.ListTables(dataSources(thisdsn))
If Ubound(tables) <> 0 Then
thistable = Lbound(tables)
Call uidoc.FieldSetText("Table", & _
tables(thistable))
End If
End Sub
REM "Table" button
Sub Click(Source As Button)
If Ubound(tables) <> 0 Then
If thistable = Ubound(tables) Then
thistable = Lbound(tables)
Else
thistable = thistable + 1
End If
Call uidoc.FieldSetText("Table", tables(thistable))
End If
End Sub
REM "List tables" action
Sub Click(Source As Button)
Dim msg As String
con.ConnectTo(dataSources(thisdsn))
If con.IsConnected Then
fields = con.ListFields(tables(thistable))
If Ubound(fields) <> 0 Then
msg = tables(thistable) & _
" contains the following fields:" & Chr(10)
For o% = Lbound(fields) To Ubound(fields)
msg = msg & Chr(10) & fields(o%)
Next
Messagebox msg,, con.DataSourceName
Else
Messagebox "No fields in " _
& tables(thistable),, _
con.DataSourceName
End If
con.Disconnect
End If
End Sub
REM "List procedures" action
Sub Click(Source As Button)
Dim msg As String
con.ConnectTo(dataSources(thisdsn))
If con.IsConnected Then
procs = con.ListProcedures
If Ubound(procs) <> 0 Then
msg = con.DataSourceName & _
" contains the following procedures:" _
& Chr(10)
For o% = Lbound(procs) To Ubound(procs)
msg = msg & Chr(10) & procs(o%)
Next
Messagebox msg,, con.DataSourceName
Else
Messagebox "No procedures",, _
con.DataSourceName
End If
con.Disconnect
End If End Sub