Having an issue when printing reports:
- First report is a letter with name and address fed through a query attached to the report
- Second report is a listing of related data connected with the account
- 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:
<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