View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
ina ina is offline
external usenet poster
 
Posts: 120
Default Call function with adodb.connection Problem

Hello guys,

I have a problem with a function that call another function

So, for exampple I have this function, info that gives me all
information about client , and this function call another function
calling getclientnumber (adodb.connection, string).

the problem is that when I call this function I have a Loop result all
the time calling the same code. I do not know why might a problem with
the adodb.connection


Public Function Info(ByVal cndb As ADODB.Connection)
On Error GoTo Info_Err

'Variables description
'======================

Dim dtmStart As Date
Dim r As Integer, i As Integer
Dim size As Integer
Dim varInfo(1 To 1000, 1 To 68) As Variant
Dim strCode As String, strCurrency As String, Name as String
Dim rsCode As ADODB.Recordset
Dim vartblFee(1 To 4, 1 To 4) As Variant

Set rsCode = New ADODB.Recordset


rsCode.ActiveConnection = cndb
rstCode.Open "select * from clientcode"


r = 2

Do While Not rsCode.EOF

strCode = rsCode.Fields(1).Value
rsCode.MoveNext

strClientNumber = GetClientNumber(cndb, strtCode)
Name = rsCode.Fields(2).Value


Cells(r, 1) = strtCode
Cells(r, 2) = Name
Cells(r, 3) = ""
Cells(r, 4) = ""
Cells(r, 5) = ""
Cells(r, 6) = ""
Cells(r, 7) = strClientNumber

r = r + 1

Loop


rsCode.Close
Set rsCode = Nothing

cndb.Close
Set cndb = Nothing

Info_Err:
'ActiveCell.Value = CVErr(xlErrNA)

End Function



'Function GetClientNumber

Public Function GetClientNumber(ByVal cndb As ADODB.Connection, strCode
As String) As String
On Error GoTo GetClientNumber_Err

Dim strSQL As String
Dim rsClient As ADODB.Recordset
Dim strClientNumber As String, strClientCall As String


Set rsClient = New ADODB.Recordset


strSQL = "select clientnumber from Clientview where code = '" & strCode
& " '"


rsClient.ActiveConnection = cndb
rsClient.Open strSQL
strClient = rs.Fields(0).Value

strClientCall = GetClientNumber(cndb, strClient) 'problem here

rsClient.Close
cndb.Close

Set cndb = Nothing
Set rsClient = Nothing

Getcurrrency_Err:
GetClientNumber = CVErr(xlErrNA)
Exit Function

End Function

Any help is appreciated thank you :)

Ina