Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: SV: Function returns recordset...


Message #1 by goran.osterman@t... on Thu, 2 May 2002 13:39:09 +0200
This is a multi-part message in MIME format.

------=_NextPart_000_002F_01C1F1DE.BCFA0460
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 8bit

RE: [pro_vb] Re: Difference between Left and Left$ functionsKali spera
George,

Take a look at an example I've used, I believe that's what you're trying to
achieve. Using .Clone as Peter mentioned, is also a good solution but I've
never used it.

Look over your variable declaration (you're using rets and retrs and I
assume you intend only one variable).

Public Function InitPlayer(ByRef rsDb As Recordset, _
                           ByVal Team As Long) As Recordset
Dim sQl As String

    On Error GoTo InitPlayerErr
    Set rsPlayer = New ADODB.Recordset
    sQl = "SELECT * FROM Player WHERE TeamId=" & Team & _
          " ORDER BY PositionPrimary, LastName"
    With rsPlayer
        .CursorType = adOpenDynamic
        .Open sQl, cnFootball, adUseClient, adLockOptimistic
    End With
    Set rsDb = rsPlayer
    Exit Function

InitPlayerErr:
    Set rsPlayer = Nothing
End Function

rsDb is a parameter to the function opening the recordset. Upon return I use
rsDb to access the data, as I suspect you're trying to.
I also suspect you're not using "Require variable declaration", found under
Tools and Options, do that. It would give an error when you compile and have
misspelled a variable, which I guess you have.

Hope that helps a bit, Göran

 -----Ursprungligt meddelande-----
Från: George Theodorakopoulos [mailto:gtheo@b...]
Skickat: den 2 maj 2002 12:11
Till: professional vb
Ämne: [pro_vb] Function returns recordset...


  Hello..
  I use the following code ...
  i call a function that returns a recordset from sub "AAA" but i could not
access the data that returned  from the function....
  what goes wrong with the code???

  Thanx!!!



  Private Function returnrs() As ADODB.Recordset

  Dim rs As ADODB.Recordset
  Dim cn As ADODB.Connection

  Set cn = New ADODB.Connection
  cn.ConnectionString = "Provider=SQLOLEDB.1;Integrated
Security=SSPI;Persist Security Info=False;User ID=ggggghjgh;Initial
Catalog=Northwind;Data Source=MYSERVER"
  cn.Open

  Set rs = New ADODB.Recordset
  rs.Open "Select * from tblusers", cn
  Set rets = rs


  rs.Close
  Set rs = Nothing
  cn.Close
  Set cn = Nothing

  End Function

  Private Sub AAA
  Dim rs1 As ADODB.Recordset

  Set rs1 = New ADODB.Recordset
  Set rs1 = retrs
  L1.Clear
  While Not rs1.EOF
      Listbox1.AddItem rs1.Fields(3)
  retrs.MoveNext
  Wend

  Set rs1 = Nothing
  End Sub



  Return to Index