ThriftyFinanceGirl said:
Well that's what I thought, but it stops... (at the rst.movenext) Can you
see it?
Set rst = Forms!frmWorkWithTax.RecordsetClone
Do While Not rst.EOF ' Iterate through each element.
dblBusUnit = Forms!frmWorkWithTax!BusUnit
intTaxID = rst!TaxID
varExFrRecon = rst!ExcludeFromRecon
'check the length of TaxID
If Len(Nz(intTaxID, "")) <> 0 Then
strWhere3 = "WHERE ([LocationObjects]![TaxID] = " &
intTaxID & ")"
strWhere4 = "WHERE ([TaxRatesBases]![TaxID] = " &
intTaxID & ")"
End If
'if the tax is marked "exclude from Recon" skip all this
below
If varExFrRecon = False Then
If DCount("Taxable", "LocationObjects", "TaxID = " &
intTaxID) < 1 Then
'there are no LocationObjects for this tax
DoCmd.OpenForm "qryCopyLocObjGROUP", , , "[taxid] =
" & CopyTaxID & ""
Set rst2 = Forms!qryCopyLocObjGROUP.RecordsetClone
Do While Not rst2.EOF ' Iterate through each
element.
intObjID = Forms!qryCopyLocObjGROUP.ObjectAcctNo
TaxYN = Forms!qryCopyLocObjGROUP.Taxable
If IsNull(Forms!qryCopyLocObjGROUP.StartTaxM) Then
intStartM = 0
intStartY = 0
'create the copied record with the new Tax Rate
ID
DoCmd.RunSQL ("INSERT INTO LocationObjects
(busunit, taxid, objectacctno, taxable) " & _
"SELECT " & dblBusUnit & " AS busunit,
"
& intTaxID & " AS taxid, " & _
"" & intObjID & " AS objectacctno, " &
TaxYN & " AS taxable;")
Else
intStartM = Forms!qryCopyLocObjGROUP.StartTaxM
intStartY = Forms!qryCopyLocObjGROUP.StartTaxY
'create the copied record with the new Tax Rate
ID
DoCmd.RunSQL ("INSERT INTO LocationObjects
(busunit, taxid, starttaxm, starttaxy, objectacctno, taxable) " & _
"SELECT " & dblBusUnit & " AS busunit,
"
& intTaxID & " AS taxid, " & intStartM & " AS " & _
"starttaxm, " & intStartY & " AS
starttaxy, " & intObjID & " AS objectacctno, " & TaxYN & " AS taxable;")
End If
rst2.MoveNext
If (rst2.EOF) = False Then
Forms!qryCopyLocObjGROUP.Bookmark =
rst2.Bookmark
End If
Loop
rst2.Close
DoCmd.Close acForm, "qryCopyLocObjGROUP"
Else
'there are LocationObjects for this tax
'check the next record
End If
End If
rst.MoveNext
If (rst.EOF) = False Then
Forms!frmWorkWithTax.Bookmark = rst.Bookmark
End If
Loop
rst.Close
What do you mean "it stops"? Is there an error raise? If so, what is it?
Looking at your code, it seems to me you that you are probably going about
this the wrong way. You seem to be using the forms' recordsetclones
primarily to navigate sequentially through the forms, and you're opening and
closing form "qryCopyLocObjGROUP" over and over again. Is there something
on the forms that you can't get by opening a query alone? This kind of
record-by-record processing can often be handled by a single, properly
contstructed update or append query. Even if it can't, and you need to loop
through a recordset, you usually don't need to use a form to do it. And if
you do need to use a form's records, you do not normally need to use the
recordsetclone just to loop through them.
As an aside, you should not ever close the form's recordsetclone. You
shouldn't be closing either rst or rst2. It may be worthwhile explicitly
setting rst2 to Nothing between iterations of the outer loop, though
technically that should not be necessary.
--
Dirk Goldgar, MS Access MVP
Access tips:
www.datagnostics.com/tips.html
(please reply to the newsgroup)