home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1997 November
/
Pcwk1197.iso
/
LOTUS
/
Eng-ins
/
SAMPLES
/
SUITE
/
DW08_S3.LSS
< prev
next >
Wrap
Text File
|
1996-08-01
|
3KB
|
78 lines
Sub Click(Source As Button, X As Long, Y As Long, Flags As Long)
' Click event for any button object
' * RUNTIME DEPENDENCIES
' * Files: This script requires an ODBC database named Sample
' * in the same directory as the .APR file. The database contains
' * a table named USERID.CUSTOMER. The table contains the
' * fields State and SaleRep.
Dim fName As String
Dim Con As New Connection
Dim Qry As New Query
Dim Rs As New ResultSet
Dim ChkSetV As Integer
Dim MyVal As Variant
Dim I As Integer ' Index to table rows
Dim TextToMatch As String
' Determine the find condition.
' Note: Here you can use some value in the current .APR to evaluate
' changes in the other file.
' For example, use "If MyVal = Val(Source.field1.text) Then"
TextToMatch = "CA"
' Open a connection to the table.
If (Con.ConnectTo ("ODBC Data Sources","userid", _
"password", "!Sample")<>False) Then
' Use this connection for the query.
Set Qry.Connection = con
' Specify the table for the query.
Qry.TableName = "USERID.CUSTOMER"
' Use this query to create the result set.
Set Rs.Query = Qry
' Create the result set.
' If the query was successful, then...
If ((rs.Execute)<>False) Then
' Find the number of columns (fields) in the table.
N = Rs.NumColumns
' Print the number of columns to the output panel of the IDE.
Print "Number of columns = ", N
' Print the names of each field in the table.
For I= 1 To N
fName = Rs.Fieldname (I)
Print fName ' Output appears in the IDE.
Next
Else ' If the result set was not successful, warn the user.
Messagebox "The query did not succeed.", _
MB_OK + MB_ICONINFORMATION + MB_APPLMODAL, _
"Unsuccessful Query"
End If ' If the result set was successful.
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.
' Read the value in a field and check if it matches the value.
' Continue while the variable i is less than or equal to the number ' of rows in the table.
For I = 1 To Rs.NumRows
Print I
' Get the value of the field State.
MyVal = Rs.GetValue("State")
Print MyVal
' If the value in the field matches the find condition, then
' set the value of another field.
If MyVal = TextToMatch Then
' Set the field "SalesRep" to the value SF.
Rs.SetValue "SalesRep", "SF"
End If ' The field value matches.
' Update the current row and move to the next one.
' UpdateRow is required to commit the changes for each record.
Rs.UpdateRow
Rs.NextRow
Next ' Until there are no more rows in the table
' Disconnect here to avoid trouble reconnecting later.
Con.Disconnect
End Sub