Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2003
    Posts
    3

    Unanswered: How to open recordset and loop through

    I how do I open a recordset in a VBA module, loop through the records..... etc.

  2. #2
    Join Date
    Sep 2003
    Location
    T.O.
    Posts
    326
    Check this link:
    http://msdn.microsoft.com/library/de...adoupdate.asp, and look under
    Retrieving and Modifying Data --> Opening a Recordset
    All code ADO/ADOX unless otherwise specified.
    Mike.

  3. #3
    Join Date
    Aug 2003
    Location
    Argentina
    Posts
    465
    I send a code that add or modify records in a Table.


    Option Compare Database
    Option Explicit
    Function AsigAgrega()
    Dim dbs As Database, rst As Recordset, rst1 As Recordset
    Dim strCodigo As Long, strTitulo As Long


    Set dbs = DBEngine.Workspaces(0).OpenDatabase("C:\GralRoca\A genbase.mdb")

    Set rst = dbs.OpenRecordset("Tbl Asignaciones", dbOpenTable)
    Set rst1 = dbs.OpenRecordset("Tbl Vendedores", dbOpenTable)

    rst.Index = "PrimaryKey"
    rst1.Index = "PrimaryKey"


    Do Until rst1.eof

    strCodigo = rst1![CODVEN]
    strTitulo = Forms![AsignacionesTitulos]![SeleccionarTiT]

    rst.Seek "=", strCodigo, strTitulo
    If rst.NoMatch Then

    With rst
    .AddNew

    !CODVEN = rst1![CODVEN]
    !CODTIT = strTitulo
    !PERASI = 0
    !TEMASI = 0
    If rst1![CODREC] = 2 Or rst1![CODREC] = 4 Then
    !RECASI = True
    Else
    !RECASI = False
    End If

    .Update
    .Bookmark = .LastModified
    End With
    GoTo Salto
    End If
    If rst1![CODREC] = 2 Or rst1![CODREC] = 4 Then
    GoTo Salto
    End If
    With rst
    .Edit
    If rst1![CODREC] = 2 Or rst1![CODREC] = 4 Then
    !RECASI = True
    Else
    !RECASI = False
    End If

    .Update
    .Bookmark = .LastModified
    End With
    Salto:
    rst1.MoveNext
    Loop

    rst.Close
    rst1.Close
    Set dbs = Nothing

    End Function
    Saludos
    Norberto

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •