Looping through a recordset

mohobrien

Registered User.
Local time
Yesterday, 17:29
Joined
Dec 28, 2003
Messages
58
I have a form with a sub form and sub-subforms.
My main form's recordsource is simply a two field table. A keyfield that is 1-1 with the subform keyfield and an autonumber ID field. This was so that I can do an editable qbf on bound fields in all forms/subforms. This works fine.
I need to track the previous record entered when adding new records. No matter what I tried with .tag, the value was overwritten by the current record as the main table and subtables were updated before I needed the .tag value. So I tried this below.

Code:
Dim db As Database
Dim qdfLastDispos As QueryDef
Dim strLastDispos As String
Dim SQLMakeTblStr As String
Dim SQLUpdateStr As String
Dim SQLAppendStr As String
Dim rst As Recordset
Dim LastDisposNumber As String
Set db = CurrentDb()
Set qdfLastDispos = db.CreateQueryDef("")
strLastDispos = "SELECT tblDispNumOnly.DispNumID, tblDispNumOnly.DispNum " & _
                "FROM tblDispNumOnly ORDER BY tblDispNumOnly.DispNumID DESC "
        With qdfLastDispos
            .SQL = strLastDispos
        End With
        Set rst = qdfLastDispos.OpenRecordset()
    With rst
        Do While Not .EOF
        Debug.Print .OpenRecordset.RecordCount
        Debug.Print .OpenRecordset.Fields(1).Value
        .MoveNext
        Loop
    End With
    rst.Close
When I write to a non-temp query, the records all show. Something is wrong with my looping through the recordset because I only get one record, the current one. I'm darned if I can see what I've done wrong.
 

Users who are viewing this thread

Back
Top Bottom