home *** CD-ROM | disk | FTP | other *** search
- Sub Click(Source As Button, X As Long, Y As Long, Flags As Long)
- ' Declare objects for a Connection, Query, and ResultSet.
- Dim MyConnection As New Connection
- Dim MyQuery As New Query
- Dim MyResultSet As New ResultSet
-
- ' Declare a set of variables for an array, and for the parameters of
- ' the above objects.
- Dim MyArray As Variant ' Array for temporary storage.
- Dim MyPath As String ' Data source path.
- Dim MyDatabaseSource As String ' Current data source type.
- Dim MyDatabase As String ' Database name.
- Dim MyTable As String ' Table name.
- Dim MyUserId As String ' User login name.
- Dim MyPassword As String ' User password.
- Dim i As Integer ' MyArray index.
- Dim LastName As String ' Data retrieved from table.
- Dim FirstName As String ' Data retrieved from table.
-
- ' Print a list of data source types available in the output panel
- ' of the IDE. Use this list to determine the exact string required
- ' (in the ConnectTo method) to make the connection to the data source.
- MyArray = MyConnection.ListDataSources()
- ' Use LotusScript functions Lbound (lower bound) and Ubound (upper
- ' bound) to determine the limits of the data source types array.
- For i = Lbound(MyArray) To Ubound(MyArray)
- ' Print the data source types to the output panel of the IDE.
- Print "Data source("i") = "MyArray(i)
- Next
-
- ' Set the parameters for the connection object.
- ' Tip: You could use an input box to get this information from the
- ' user and connect to whatever the user specifies.
- MyDatabaseSource = "Lotus Notes - Local"
- ' Change this path to match your operating system.
- MyPath = "C:\NOTES\DATA\"
- MyDatabase = "NAMES.NSF"
- ' This table has no user or password requirements, so these strings
- ' are blank.
- MyUserId = ""
- MyPassword = ""
-
- ' Connect to the database.
- If MyConnection.ConnectTo(MyDatabaseSource, MyUserId, MyPassword,_
- MyPath & MyDatabase) Then
- ' List the available tables in the database.
- MyArray = MyConnection.ListTables()
- For i = Lbound(MyArray) To Ubound(MyArray)
- ' Print the data source types to the output panel of the IDE.
- Print "Table("i") = "MyArray(i)
- Next
-
- ' Specify the table that data will be extracted from.
- MyTable = "People"
- ' Set the Connection property of the Query object to
- ' the current connection.
- Set MyQuery.Connection = MyConnection
- ' Specify the table to be searched, including path.
- ' The ampersand (&) concatenates pieces of the string.
- MyQuery.TableName = MyPath & MyDatabase & "\" & MyTable
- ' Set the Query property of the result set to the current query.
- Set MyResultSet.Query = MyQuery
- ' Get the data from the table and put it in the result set.
-
-
- If (MyResultSet.Execute) Then
- ' Make sure there is data in the table.
- If (MyResultSet.NumRows) Then
- ' Start at the first row.
- MyResultSet.FirstRow
- ' Loop through the records and get the values from
- ' the First_Name and Last_Name fields.
- Do
- LastName = MyResultSet.GetValue("Last_Name")
- FirstName = MyResultSet.GetValue("First_Name")
- ' Print the data to the output panel of the IDE.
- Print "Person" MyResultSet.CurrentRow "in the table is "_
- &FirstName " " &LastName
- ' Continue looping until there are no more rows.
- Loop While MyResultSet.NextRow
- Else
- ' If the table is empty, warn the user
- Messagebox "The table is empty.", MB_OK + _
- MB_ICONINFORMATION + MB_APPLMODAL, "Empty Table"
- End If ' If there is data in the table.
- Else
- ' If the result set was not successful, warn the user.
- Messagebox "The query did not succeed. Check the " & _
- "connection.", MB_OK + MB_ICONINFORMATION + MB_APPLMODAL, _
- "Unsuccessful Query"
- End If ' If the result set was successful.
- Call MyConnection.Disconnect()
-
- Else
- ' If the connection was not successful, warn the user.
- Messagebox "Connection failed", MB_OK + MB_ICONINFORMATION + _
- MB_APPLMODAL, "Connection"
-
- End If ' If the connection was successful.
- End Sub
-