tatendatiffany
Board Regular
- Joined
- Mar 27, 2011
- Messages
- 103
Hi,
could some one help me i am facing a problem on my code "object required" but i have specified in the function what could i have done wrong: the line higlighted in bold is where i am getting the error but i thought i had specified in the function the recordset??
could some one help me i am facing a problem on my code "object required" but i have specified in the function what could i have done wrong: the line higlighted in bold is where i am getting the error but i thought i had specified in the function the recordset??
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;" 'Assumption based on your connection string being valid
.Provider = "IBMDADB2.DB2COPY1" 'assumption based on your provider being correct
' .Open 'if the above are true then this will open DB
'End With
[B]Set rs = Db.OpenRecordset
[/B] 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