Back to the loop that doesn't loop

T

TeeSee

A couple of weeks ago I posted a looping code that I couldn't get
right and I was steered (thankfully) towards SQL which I have made
great use of since, however I didn't actually learn what I was doing
wrong with the loopy code.
I have a similar problem again now and the problem specifically
is ......

I can't get off the first record!

The code compiles (honest). The recordset is what I expect. The
recordcount is correct. As the code steps thru its cycle I can see in
the Immediate window that the values are changing from -1 to 0 and
then on the second cycle back from 0 to -1. My item code shows that
both cycles are for record 1

Could someone please explain
 
T

TeeSee

A couple of weeks ago I posted a looping code that I couldn't get
right and I was steered (thankfully) towards SQL which I have made
great use of since, however I didn't actually learn what I was doing
wrong with the loopy code.
I have a similar problem again now and the problem specifically
is ......

I can't get off the first record!

The code compiles (honest). The recordset is what I expect. The
recordcount is correct. As the code steps thru its cycle I can see in
the Immediate window that the values are changing from -1 to 0 and
then on the second cycle back from 0 to -1. My item code shows that
both cycles are for record 1

Could someone please explain

Sorry ...I forgot to add the code. Time for bed!


Private Sub Command4_Click()
Dim rs As DAO.Recordset
Dim X As Integer

Set rs = Me.RecordsetClone

Debug.Print rs.RecordCount
rs.MoveFirst
For X = 1 To rs.RecordCount

Debug.Print SISItemCode.Value
If Me.Check2 = True Then

Debug.Print Me!Check2.Value
Me.Check2 = False
Debug.Print Me!Check2.Value
ElseIf Me.Check2 = False Then
Debug.Print Me!Check2.Value
Me.Check2 = True
Debug.Print Me!Check2.Value
End If
rs.MoveNext
Next X
End Sub
 
G

Gina Whipp

TeeSee,

I'm not sure I understand what you are trying to do...

If Check2 = False you want to change to True and visa versa?

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index.htm

A couple of weeks ago I posted a looping code that I couldn't get
right and I was steered (thankfully) towards SQL which I have made
great use of since, however I didn't actually learn what I was doing
wrong with the loopy code.
I have a similar problem again now and the problem specifically
is ......

I can't get off the first record!

The code compiles (honest). The recordset is what I expect. The
recordcount is correct. As the code steps thru its cycle I can see in
the Immediate window that the values are changing from -1 to 0 and
then on the second cycle back from 0 to -1. My item code shows that
both cycles are for record 1

Could someone please explain

Sorry ...I forgot to add the code. Time for bed!


Private Sub Command4_Click()
Dim rs As DAO.Recordset
Dim X As Integer

Set rs = Me.RecordsetClone

Debug.Print rs.RecordCount
rs.MoveFirst
For X = 1 To rs.RecordCount

Debug.Print SISItemCode.Value
If Me.Check2 = True Then

Debug.Print Me!Check2.Value
Me.Check2 = False
Debug.Print Me!Check2.Value
ElseIf Me.Check2 = False Then
Debug.Print Me!Check2.Value
Me.Check2 = True
Debug.Print Me!Check2.Value
End If
rs.MoveNext
Next X
End Sub
 
T

TeeSee

TeeSee,

I'm not sure I understand what you are trying to do...

If Check2 = False you want to change to True and visa versa?

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index.htm







Sorry ...I forgot to add the code. Time for bed!

Private Sub Command4_Click()
    Dim rs As DAO.Recordset
    Dim X As Integer

    Set rs = Me.RecordsetClone

    Debug.Print rs.RecordCount
    rs.MoveFirst
    For X = 1 To rs.RecordCount

        Debug.Print SISItemCode.Value
        If Me.Check2 = True Then

            Debug.Print Me!Check2.Value
            Me.Check2 = False
            Debug.Print Me!Check2.Value
        ElseIf Me.Check2 = False Then
            Debug.Print Me!Check2.Value
            Me.Check2 = True
            Debug.Print Me!Check2.Value
        End If
            rs.MoveNext
    Next X
End Sub- Hide quoted text -

- Show quoted text -

That is correct! Don't take this next question the wrong way please.
Regardless of what I'm trying to do all I would really like an answer
to is why can't i get past the first record??

Thanks for responding.
 
G

Gina Whipp

Dim rs As DAO.Recordset
Dim X As Integer

Set rs = Me.RecordsetClone <<<<<<<< change to Me.Recordset

Debug.Print rs.RecordCount
rs.MoveFirst
For X = 1 To rs.RecordCount

Debug.Print SISItemCode.Value
If Me.Check2 = True Then

Debug.Print Me!Check2.Value
Me.Check2 = False
Debug.Print Me!Check2.Value
ElseIf Me.Check2 = False Then
Debug.Print Me!Check2.Value
Me.Check2 = True
Debug.Print Me!Check2.Value
End If
rs.MoveNext
Next X


--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index.htm

TeeSee,

I'm not sure I understand what you are trying to do...

If Check2 = False you want to change to True and visa versa?

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index.htm







Sorry ...I forgot to add the code. Time for bed!

Private Sub Command4_Click()
Dim rs As DAO.Recordset
Dim X As Integer

Set rs = Me.RecordsetClone

Debug.Print rs.RecordCount
rs.MoveFirst
For X = 1 To rs.RecordCount

Debug.Print SISItemCode.Value
If Me.Check2 = True Then

Debug.Print Me!Check2.Value
Me.Check2 = False
Debug.Print Me!Check2.Value
ElseIf Me.Check2 = False Then
Debug.Print Me!Check2.Value
Me.Check2 = True
Debug.Print Me!Check2.Value
End If
rs.MoveNext
Next X
End Sub- Hide quoted text -

- Show quoted text -

That is correct! Don't take this next question the wrong way please.
Regardless of what I'm trying to do all I would really like an answer
to is why can't i get past the first record??

Thanks for responding.
 
G

Gina Whipp

Oops, forgot...

This might help in understanding the difference between a RecordsetClone and
a Recordset: http://www.fmsinc.com/free/newtips/Access/accesstip26.asp

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index.htm

TeeSee,

I'm not sure I understand what you are trying to do...

If Check2 = False you want to change to True and visa versa?

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index.htm







Sorry ...I forgot to add the code. Time for bed!

Private Sub Command4_Click()
Dim rs As DAO.Recordset
Dim X As Integer

Set rs = Me.RecordsetClone

Debug.Print rs.RecordCount
rs.MoveFirst
For X = 1 To rs.RecordCount

Debug.Print SISItemCode.Value
If Me.Check2 = True Then

Debug.Print Me!Check2.Value
Me.Check2 = False
Debug.Print Me!Check2.Value
ElseIf Me.Check2 = False Then
Debug.Print Me!Check2.Value
Me.Check2 = True
Debug.Print Me!Check2.Value
End If
rs.MoveNext
Next X
End Sub- Hide quoted text -

- Show quoted text -

That is correct! Don't take this next question the wrong way please.
Regardless of what I'm trying to do all I would really like an answer
to is why can't i get past the first record??

Thanks for responding.
 
J

John Spencer (MVP)

Private Sub Command4_Click()
Dim rs As DAO.Recordset
Dim X As Integer

Set rs = Me.RecordsetClone

rs.MoveLast 'force recordset to load all records
'so you get an accurate count of the records

Debug.Print rs.RecordCount
rs.MoveFirst
For X = 1 To rs.RecordCount

Debug.Print SISItemCode.Value
If Me.Check2 = True Then

Debug.Print Me!Check2.Value
Me.Check2 = False
Debug.Print Me!Check2.Value
ElseIf Me.Check2 = False Then
Debug.Print Me!Check2.Value
Me.Check2 = True
Debug.Print Me!Check2.Value
End If
rs.MoveNext
Next X
End Sub



John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 
T

TeeSee

Oops, forgot...

This might help in understanding the difference between a RecordsetClone and
a Recordset:  http://www.fmsinc.com/free/newtips/Access/accesstip26.asp

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index.htm














That is correct! Don't take this next question the wrong way please.
Regardless of what I'm trying to do all I would really like an answer
to is why can't i get past the first record??

Thanks for responding.- Hide quoted text -

- Show quoted text -

Many thanks Gina. The loopy code now loops. Thanks also for the info
re rs'clone
 
A

AccessVandal via AccessMonster.com

If you use the RecordSetCone method instead of Recordset, you need to use the
bookmark property of the form.

If Me.chk1 = True Then
Debug.Print Me!chk1.Value
Me.chk1 = False
Debug.Print Me!chk1.Value
ElseIf Me.chk1 = False Then
Debug.Print Me!chk1.Value
Me.chk1 = True
Debug.Print Me!chk1.Value
End If
Me.Bookmark = rs.Bookmark '<<<<
rs.MoveNext

However, use it with caution as it will also mark the new record if you are
in the new record.
 
G

Gina Whipp

Your welcime!

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

Oops, forgot...

This might help in understanding the difference between a RecordsetClone
and
a Recordset: http://www.fmsinc.com/free/newtips/Access/accesstip26.asp

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index.htm














That is correct! Don't take this next question the wrong way please.
Regardless of what I'm trying to do all I would really like an answer
to is why can't i get past the first record??

Thanks for responding.- Hide quoted text -

- Show quoted text -

Many thanks Gina. The loopy code now loops. Thanks also for the info
re rs'clone
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top