Andre’s Weblog

Método Find, solo acepta 1 parámetro

Posteado por: andre223 en: Octubre 3, 2008

Utilice la propiedad de filtro de ADO y el método de clonación. Así, se puede encontrar el marcador correcto en el clon sin que ello afecte a las filas que están visibles en el conjunto de registros.

Un ejemplo de código que muestra este método siguiente:

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

      'Create a variable for the Cloned Recordset.
      Dim clone_rs As ADODB.Recordset

      Set cn = CreateObject("ADODB.Connection")
      Set rs = CreateObject("ADODB.Recordset")

      With cn
       .ConnectionString = "PROVIDER=SQLOLEDB;" & _
                           "DATA SOURCE=<server>;" & _
                           "USER ID=<uid>;" & _
                           "PASSWORD=<pwd>;" & _
                           "INITIAL CATALOG=<init_cat>"
       .Open
      End With

      With rs
       .CursorLocation = adUseClient
       .CursorType = adOpenStatic
       .LockType = adLockBatchOptimistic
       .ActiveConnection = cn
       .Open "select * from authors"
      End With

      'A clone recordset has some benefits :
      ' - Very little overhead, it is only an object variable containning a
      '   reference to the original recordset.
      ' - It does not require another round trip to the server.
      ' - It maintains separate but shareable bookmarks with the original.
      ' - Closing and filtering clones does not affect the original or
      '   other clones.

      'Create a clone of the recordset.
      Set clone_rs = Rs.Clone
      'Apply a filter to the clone using the criteria passed in.
      clone_rs.Filter = "state = 'CA' AND city = 'Oakland'"

      If clone_rs.EOF Or clone_rs.BOF Then
      'If criteria not found move to EOF; just as ADO's Find
       rs.MoveLast
       rs.MoveNext
      Else
      'If found, move the Recordset's bookmark to the same location as the
      'clone's bookmark.
      rs.Bookmark = clone_rs.Bookmark
      End If

      clone_rs.Close
      Set clone_rs = Nothing

      rs.Close
      cn.Close

      Set rs = Nothing
      Set cn = Nothing

      End Sub

fuente: http://support.microsoft.com/kb/195222/es

Escribe un comentario