2013-07-23 70 views
2

我有代碼需要一張表,並重新排列表以形成一個新表。它使用少量的數據,但現在我試圖用超過1,000條記錄運行相同的代碼,它得到錯誤28「堆棧空間不足」。我不會在這裏複製我所有的代碼,因爲它太過分了,我認爲沒有必要,除非您另有想法。我認爲這是我的遞歸的一個問題。我需要這個,因爲一個DONOR_CONTACT_ID只能有4個收件人,如果它有多個,那麼它必須創建一個具有相同DONOR_CONTACT_ID的新記錄並填充收件人。如何修復「堆棧空間不足」錯誤?

這是這是越來越錯誤的子過程:

Sub NextDonor() 

With rstOutput 
.FindNext "[DONOR_CONTACT_ID] = " & strDonor2 
'Find the next record in T_OUTPUT with that DONOR_CONTACT_ID 

      If .NoMatch Then 
       'If there are no more records with that DONOR_CONTACT_ID, add a new one 
       .AddNew 
       !DONOR_CONTACT_ID = strDonor1 
       !RECIPIENT_1 = strRecip1 
       !ORDER_NUMBER = strOrderNum1 
       .Update 
      Else 
      'A second DONOR_CONTACT_ID in T_OUTPUT exists. Check to see if all fields are filled. 
       If !DONOR_CONTACT_ID = strDonor2 Then 
        If IsNull(!RECIPIENT_2) And Not (IsNull(!RECIPIENT_1)) Then 
        'RECIPIENT_2 is empty, so populate it 
         .Edit 
         !RECIPIENT_2 = strRecip1 
         .Update 

        ElseIf IsNull(!RECIPIENT_3) And Not (IsNull(!RECIPIENT_2)) Then 
        'RECIPIENT_3 is empty, so populate it 
         .Edit 
         !RECIPIENT_3 = strRecip1 
         .Update 
        ElseIf IsNull(!RECIPIENT_4) And Not (IsNull(!RECIPIENT_3)) Then 
        'RECIPIENT_4 is empty, so populate it 
         .Edit 
         !RECIPIENT_4 = strRecip1 
         .Update 

        ElseIf Not IsNull(!RECIPIENT_4) Then 
        'RECIPIENT_4 is filled, so run this function again 
         Call NextDonor 
        End If 

       End If 
      End If 
End With 
End Sub 

的錯誤是在那裏說「叫NextDonor」,可能是因爲遞歸的線。如果您需要我澄清我的代碼試圖執行的操作,或者如果您希望我複製代碼的其他部分,請告訴我。

回答

3

試試這個,以避免遞歸...

Sub NextDonor(byref Again as Boolean) 
With rstOutput 
DoItAgain : 
.FindNext "[DONOR_CONTACT_ID] = " & strDonor2 

    If .... 
    .... 
    ElseIf Not IsNull(!RECIPIENT_4) Then 
    'RECIPIENT_4 is filled, so run this function again 
    Goto DoItAgain 
    End If 
End Sub 
0

其實你的遞歸代碼和1回答都跳過收件人如果第4槽滿了,你遍歷另一個查找和你失去當前收件人!這也消除了遞歸。 改爲:

If .NoMatch or (not isnull(!recipient_4)Then 
      'If there are no more records with that DONOR_CONTACT_ID, add a new one 
      ' or current record is full 
      .AddNew 
      !DONOR_CONTACT_ID = strDonor1 
      !RECIPIENT_1 = strRecip1 
      !ORDER_NUMBER = strOrderNum1 
      .Update 
     Else 
相關問題