tatendatiffany
Board Regular
- Joined
- Mar 27, 2011
- Messages
- 103
ok so i am having difficulties with creating a recordset for a function. The recordset is suppose to execute the strings returned from the look up
the function is
and the whole code is
how to a create a recordset for the function i have. I want it to execute the returned results (being sql queries)
the function is
Code:
getrecordset
and the whole code is
Code:
Function getrecordset(str) As String
'create recordset object
Dim rs As adodb.Recordset
Set rs = New adodb.Recordset
With rs
.ActiveConnection = cn
'using the str variable open the recordset
.Source = str
.Open
End With
'if recordset NOT NULL
If Not (rs.BOF And rs.EOF) Then
getrecordset = rs(0)
getrecordset = Recordset
'else
'getrecordset = "No Result"
getrecordset = vbNullString
End If
'close and destroy recordset object
Set rs = Nothing
End Function
Sub getresults()
Dim r As Integer 'row counter
Dim c As Integer 'column counter
Dim str As String
Dim rs As Recordset
Dim cn As adodb.Connection
Set cn = New adodb.Connection
With cn
.ConnectionString = "Password=" & password & ";Persist Security Info=True;User ID=" & username & ";Data Source=" & DatabaseEnv & ";Mode=ReadWrite;"
.Provider = "IBMDADB2.DB2COPY1"
' .Open
'End With
rs = "select * from worksheet" & Range("Environ1") & ("Environ3") & ("Environ4") & ("Environ5") & ("Environ7")
Set rs = Db.OpenRecordset
For c = 31 To 35 'columns AE to AI
For r = 2 To 39 'start with first row
If Cells(r, c).Value <> "" Then 'is there a value in the row?
str = Cells(r, c).Value 'this is the SQL string we need for the recordset
Cells(r, c - 5).Value = getrecordset(str) 'use a function to open the recordset and return the value to column 3
End If
Next r
Next c 'next column
End With
End Sub
how to a create a recordset for the function i have. I want it to execute the returned results (being sql queries)