Sub Click(Source As Button) Dim cn As Variant Dim rs As Variant Dim strSQL As String Dim strEmployeeID As String Dim ws As New NotesUIWorkspace Dim uidoc As NotesUIDocument
Set uidoc = ws.CurrentDocument Set cn = CreateObject("ADODB.Connection") Set rs = CreateObject("ADODB.Recordset")
On Error Goto ConnectionErr 'SQLServer接続文字列 cn.ConnectionString = "Provider=SQLOLEDB ;" & _ "Password='' ; User ID=sa;Initial Catalog=Northwind;Data Source=SQLServer" strEmployeeID = Trim(uidoc.FieldGetText("EmployeeID"))
'SQL文 strSQL = "SELECT EmployeeID, LastName " & _ "FROM dbo.Employees " & _ "WHERE (EmployeeID = " & strEmployeeID & ")"
'接続開始 Call cn.Open 'SQL文発行 Call rs.Open(strSQL,cn) '取得した値をフィールドにセット Call uidoc.FieldSetText("LastName",Trim(rs.Fields("LastName").Value)) 'Recordsetクローズ Call rs.Close 'Connectionクローズ Call cn.Close '文書を更新する Call uidoc.Refresh
ConnectionExit: Exit Sub
ConnectionErr: Resume ConnectionExit End Sub |