VBA Code stops running after printing report imbedded in Loop

Having an issue when printing reports:

  1. First report is a letter with name and address fed through a query attached to the report
  2. Second report is a listing of related data connected with the account
  3. third report is blank and just informational

If there is no data connected with the account, the second report still prints only with a tag that says there is no info.

Code below:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Private Sub cmdPreview_Click()
Dim strSQL As String
Dim rstParticipantInfo As DAO.Recordset
strSQL = "SQL Query to pull data set - Testing has 2 account holders"
Set rstParticipantInfo = CurrentDb.OpenRecordset(strSQL)
rstParticipantInfo.MoveFirst
Do Until rstParticipantInfo.EOF
Call fnPullInfo(rstParticipantInfo!SSNO)
rstParticipantInfo.MoveNext
Loop
End Sub
Public Function fnPullInfo(ByRef rstParticipantInfo)
Dim rst As DAO.Recordset
Dim strSQL As String
Dim strSSN As String
Dim strID As String
Dim vColumnArray As Variant
Dim x As Variant
Dim strEvalType As String
Dim strID As String
Dim strLName As String
Dim strFName As String
Dim strOrgName As String
Dim strAdd1 As String
Dim strAdd2 As String
Dim strCity As String
strSSN = rstParticipantInfo![SSNO]
strSQL = "SQL Query to pull account related data"
Set rst = CurrentDb.OpenRecordset(strSQL)
If rst.RecordCount = 0 Then
DoCmd.OpenReport "rpt_Letter1", acViewNormal, , "SSNO = " & strSSN, acWindowNormal
DoCmd.OpenReport "rpt_Letter2", acViewNormal, , "SSNO = " & strSSN, acWindowNormal
DoCmd.OpenReport "rpt_Letter3", acViewNormal, , , acWindowNormal
Else
vColumnArray = Array(13, 26, 39, 52, 65, 78, 91, 104, 117, 130, 143, 156, 169, 182, 195, 208, 221, 234, 247)
For Each x In vColumnArray
If Not IsNull(rst.Fields.Item(x)) Or Not IsNull(rst.Fields.Item(x + 2)) Then
strEvalType = Nz(rst.Fields.Item(x + 4))
strID = Nz(rst.Fields(0))
If strEvalType = "Extra Info" Then
strLName = Nz(rst.Fields.Item(x + 1)) & " " & Nz(rst.Fields.Item(x + 2))
strFName = Nz(rst.Fields.Item(x))
strOrgName = Nz(rst.Fields.Item(x + 2))
Else
strLName = Nz(rst.Fields.Item(x))
strFName = Nz(rst.Fields.Item(x + 1))
strOrgName = Nz(rst.Fields.Item(x + 2))
End If
strAdd1 = Nz(rst.Fields.Item(x + 8))
strAdd2 = Nz(rst.Fields.Item(x + 9))
strCity = Nz(rst.Fields.Item(x + 10))
DoCmd.SetWarnings False
strSQL = "INSERT SQL command to add related data in available"
DoCmd.RunSQL strSQL
Else
DoCmd.OpenReport "rpt_Letter1", acViewNormal, , "SSNO = " & rstParticipantInfo!SSNO, acWindowNormal
DoCmd.OpenReport "rpt_Letter2", acViewNormal, , "SSNO = " & rstParticipantInfo!SSNO, acWindowNormal
DoCmd.OpenReport "rpt_Letter3", acViewNormal, , , acWindowNormal
End If
Next
End If
End Function
</code>
<code>Private Sub cmdPreview_Click() Dim strSQL As String Dim rstParticipantInfo As DAO.Recordset strSQL = "SQL Query to pull data set - Testing has 2 account holders" Set rstParticipantInfo = CurrentDb.OpenRecordset(strSQL) rstParticipantInfo.MoveFirst Do Until rstParticipantInfo.EOF Call fnPullInfo(rstParticipantInfo!SSNO) rstParticipantInfo.MoveNext Loop End Sub Public Function fnPullInfo(ByRef rstParticipantInfo) Dim rst As DAO.Recordset Dim strSQL As String Dim strSSN As String Dim strID As String Dim vColumnArray As Variant Dim x As Variant Dim strEvalType As String Dim strID As String Dim strLName As String Dim strFName As String Dim strOrgName As String Dim strAdd1 As String Dim strAdd2 As String Dim strCity As String strSSN = rstParticipantInfo![SSNO] strSQL = "SQL Query to pull account related data" Set rst = CurrentDb.OpenRecordset(strSQL) If rst.RecordCount = 0 Then DoCmd.OpenReport "rpt_Letter1", acViewNormal, , "SSNO = " & strSSN, acWindowNormal DoCmd.OpenReport "rpt_Letter2", acViewNormal, , "SSNO = " & strSSN, acWindowNormal DoCmd.OpenReport "rpt_Letter3", acViewNormal, , , acWindowNormal Else vColumnArray = Array(13, 26, 39, 52, 65, 78, 91, 104, 117, 130, 143, 156, 169, 182, 195, 208, 221, 234, 247) For Each x In vColumnArray If Not IsNull(rst.Fields.Item(x)) Or Not IsNull(rst.Fields.Item(x + 2)) Then strEvalType = Nz(rst.Fields.Item(x + 4)) strID = Nz(rst.Fields(0)) If strEvalType = "Extra Info" Then strLName = Nz(rst.Fields.Item(x + 1)) & " " & Nz(rst.Fields.Item(x + 2)) strFName = Nz(rst.Fields.Item(x)) strOrgName = Nz(rst.Fields.Item(x + 2)) Else strLName = Nz(rst.Fields.Item(x)) strFName = Nz(rst.Fields.Item(x + 1)) strOrgName = Nz(rst.Fields.Item(x + 2)) End If strAdd1 = Nz(rst.Fields.Item(x + 8)) strAdd2 = Nz(rst.Fields.Item(x + 9)) strCity = Nz(rst.Fields.Item(x + 10)) DoCmd.SetWarnings False strSQL = "INSERT SQL command to add related data in available" DoCmd.RunSQL strSQL Else DoCmd.OpenReport "rpt_Letter1", acViewNormal, , "SSNO = " & rstParticipantInfo!SSNO, acWindowNormal DoCmd.OpenReport "rpt_Letter2", acViewNormal, , "SSNO = " & rstParticipantInfo!SSNO, acWindowNormal DoCmd.OpenReport "rpt_Letter3", acViewNormal, , , acWindowNormal End If Next End If End Function </code>
Private Sub cmdPreview_Click()
Dim strSQL As String
Dim rstParticipantInfo As DAO.Recordset

    strSQL = "SQL Query to pull data set - Testing has 2 account holders"

    Set rstParticipantInfo = CurrentDb.OpenRecordset(strSQL)
        
    rstParticipantInfo.MoveFirst
    Do Until rstParticipantInfo.EOF
        Call fnPullInfo(rstParticipantInfo!SSNO)
        rstParticipantInfo.MoveNext
    Loop

End Sub

Public Function fnPullInfo(ByRef rstParticipantInfo) 
Dim rst As DAO.Recordset
Dim strSQL As String
Dim strSSN As String
Dim strID As String
Dim vColumnArray As Variant
Dim x As Variant
Dim strEvalType As String
Dim strID As String
Dim strLName As String
Dim strFName As String
Dim strOrgName As String
Dim strAdd1 As String
Dim strAdd2 As String
Dim strCity As String

    strSSN = rstParticipantInfo![SSNO]
    
    strSQL = "SQL Query to pull account related data"
    Set rst = CurrentDb.OpenRecordset(strSQL)

    If rst.RecordCount = 0 Then
        DoCmd.OpenReport "rpt_Letter1", acViewNormal, , "SSNO = " & strSSN, acWindowNormal
        DoCmd.OpenReport "rpt_Letter2", acViewNormal, , "SSNO = " & strSSN, acWindowNormal
        DoCmd.OpenReport "rpt_Letter3", acViewNormal, , , acWindowNormal

    Else
        vColumnArray = Array(13, 26, 39, 52, 65, 78, 91, 104, 117, 130, 143, 156, 169, 182, 195, 208, 221, 234, 247)
        For Each x In vColumnArray
            If Not IsNull(rst.Fields.Item(x)) Or Not IsNull(rst.Fields.Item(x + 2)) Then
                strEvalType = Nz(rst.Fields.Item(x + 4))
                strID = Nz(rst.Fields(0))
                If strEvalType = "Extra Info" Then
                    strLName = Nz(rst.Fields.Item(x + 1)) & " " & Nz(rst.Fields.Item(x + 2))
                    strFName = Nz(rst.Fields.Item(x))
                    strOrgName = Nz(rst.Fields.Item(x + 2))
                Else
                    strLName = Nz(rst.Fields.Item(x))
                    strFName = Nz(rst.Fields.Item(x + 1))
                    strOrgName = Nz(rst.Fields.Item(x + 2))
                End If
                    strAdd1 = Nz(rst.Fields.Item(x + 8))
                    strAdd2 = Nz(rst.Fields.Item(x + 9))
                    strCity = Nz(rst.Fields.Item(x + 10))
                    DoCmd.SetWarnings False
                    
                    strSQL = "INSERT SQL command to add related data in available"
                    DoCmd.RunSQL strSQL
            Else
                DoCmd.OpenReport "rpt_Letter1", acViewNormal, , "SSNO = " & rstParticipantInfo!SSNO, acWindowNormal
                DoCmd.OpenReport "rpt_Letter2", acViewNormal, , "SSNO = " & rstParticipantInfo!SSNO, acWindowNormal
                DoCmd.OpenReport "rpt_Letter3", acViewNormal, , , acWindowNormal

            End If
        Next
    End If

End Function

After it pulls the first record in the record set, this one has 2 for testing purposes, the record count is 0 signifying there is no related data available – but will still print the 3 reports. The code doesn’t continue and it doesn’t loop to the next record as it should.

9

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật