On one hand you could pretty much ignore my posts. I misread the nested
loops and in doing so I completely discounted the possibility that
DoCmd.GoToRecord was actually doing anything because of 1) where it was
placed and 2) its lack of arguments (I generally avoid relying on default
arguments. No guarantees that they will be the defaults in the next version
and I find code easier to read/maintain when its specific.).
George Nicholson
I didn't understand why I do not need to use the:
"if you are in the last record don't go to the next record because a
err will occur"
Well, your code never tests to see whether you are in the last record. There
really is no such test. I think you misunderstand what EOF is...
If you want to use the status of EOF for your loop, you can't use
GoToRecord. Here's why: EOF will *never* be true while you are on a valid
record and GoToRecord won't allow you to move anywhere except valid records.
You discovered that when you issued GoToRecord while on the last record:
"Can't go there" error.
For EOF to be True, you have to move *past* the last record. That's what EOF
is: a "beyond last record" marker, not a "last record" marker.
Do Until Me.RecordsetClone.EOF
'..........lotsa code...........
If Me.RecordsetClone.EOF Then
' This condition will never happen. If EOF were true, the loop
wouldn't have been entered
' and you haven't done anythingduring this iteration to change the
EOF status
GoTo finish
Else
' If we are on the last record, this will try to execute but will
raise a "can't go to specified record" error
DoCmd.GoToRecord
End If
Loop
Using MoveNext while on the last record would *not* raise the same error. It
would actually move you past the last record, thereby allowing EOF to become
True. This allows your loop to end as you expect. This is how EOF tests are
meant to be used.
GoToRecord and MoveNext might appear to do the same thing, but they are in
different object models and have different behaviour. EOF and MoveNext work
together (and were designed to). EOF and GoToControl do not.
HTH,
On Tue, 07 Aug 2007 09:50:19 -0700, (e-mail address removed) wrote:
I have a table "pt" with 2 fields 1 named "MasterID" and 1 named
"tickets"
each MasterID hes a number of tickets to print so I want to append to
a new table each masterid so many times the value of the ticket field
is
example if the masterid "15251" hes the ticket value 20 I want to
append to the new table the value "15251" 20 times
I'd suggest a different approach altogether.
Create a table named NUM with one integer field N, with values from 0
through
some large number (10000, 65535 even).
Create a Query by adding [pt] and [Num] to the query grid, with NO join
line.
Put a criterion on N of
< [pt].[tickets]
Select MasterID and N as fields in the query.
This query will give you [tickets] copies of each record in [pt]. You can
use
the query for an export, as the recordsource for a report, as the
rowsource
for a combo, etc. - there's probably NO good reason to create a new table
at
all, much less store 20 redundant records in it.
John W. Vinson [MVP]
thanks John W. Vinson
it works
George Nicholson
I didn't understand why I do not need to use the:
"if you are in the last record don't go to the next record because a
err will occur"- Hide quoted text -
- Show quoted text -