I have a label report based on a table with 1222 records.
It should show me 41 pages - 30 labels each page, but it only shows 17 pages - 501 labels. The table really has 1222 records.
This hapens only when I run the report clicking a button in a form that calls a procedure to print the report.
When I run the VB code step by step it works well! It shows all teh 41 pages, 1222 records!
Any help?
My code behind the button:
Private Sub Comando64_Click()
On Error GoTo ErrorHandler
Dim strTable As String
Dim strReport As String
Dim ctl As Access.Control
Dim lst As Access.ListBox
Dim strTrat As String
Dim strNome As String
Dim strEnd As String
Dim strBai As String
Dim strMun As String
Dim strUF As String
Dim strCEP As String
Dim varItem As Variant
Dim intIndex As Integer
Dim intCount As Integer
Dim strWordTemplate As String
Dim strSQL As String
Dim strShortDate As String
Dim strLongDate As String
Dim strDocsPath As String
Dim strTemplatePath As String
Dim intRow As Integer
Dim intRows As Integer
Dim intColumn As Integer
Dim intColumns As Integer
Dim strTest As String
Dim strCountry As String
Dim strDocType As String
Dim strSaveName As String
Dim intSaveNameFail As String
Dim i As String
Dim strSaveNamePath As String
Dim strDocName As String
Dim strDBPath As String
Dim strTextFile As String
Dim strTestFile As String
Dim j As Integer
Dim n As Integer
Dim strGrupo As String
Set lst = Me![lstSelectContacts]
'Select all list items
SelTodosItensList
intColumns = lst.ColumnCount
intRows = lst.ItemsSelected.Count
If intRows = 0 Then
MsgBox "Choose at least one Group"
Me.grupo.SetFocus
Exit Sub
End If
'Delete all records from tblMergeList and creates a new record set
strTable = "tblMergeList"
strSQL = "DELETE tblMergeList.* FROM tblMergeList;"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
Set dbs = CurrentDb
Debug.Print "Opening recordset based on " & strTable
Set rst = dbs.OpenRecordset(strTable, dbOpenTable)
For Each varItem In lst.ItemsSelected
'Record list items in variables
strTrat = Nz(lst.Column(1, varItem))
strNome = Nz(lst.Column(2, varItem))
strEnd = Nz(lst.Column(3, varItem))
strBai = Nz(lst.Column(4, varItem))
strMun = Nz(lst.Column(5, varItem))
strUF = Nz(lst.Column(6, varItem))
strCEP = Nz(lst.Column(7, varItem))
If IsNull(strTrat) Then
strTrat = " "
End If
' 'Record data from vars in a new tblMergeList record
With rst 'com tblMergeList
.AddNew
!trat = strTrat
!nome = strNome
!end = strEnd
!bai = strBai
!mun = strMun
!uf = strUF
!cep = strCEP
.Update
End With
NextContact:
Next varItem
rst.Close
'Deselect all list items
EliminaSelItensList
intColumns = lst.ColumnCount
intRows = lst.ItemsSelected.Count
'Roda rel da etiqueta selecionada
strReport = [cboSelect_etq].[Column](1)
'Run label report in Preview mode
DoCmd.OpenReport strReport, acViewPreview
'Delete all tblMergeList records
DelTodosReg ("tblMergeList")
'Delete all PessoasMala records
DelTodosReg ("PessoasMala")
Me.lstSelectContacts.Requery
Me.qtde = ""
'Initialize var Z
Z = 0
'Deselect all list items
EliminaSelItensList
'Initialize all Combos
Me.grupo = 0
Me.cargo = 0
Me.mun = 0
''Initialize field nome_grupo
Me.nome_grupo = ""
Me.cboSelect_etq = 0
ErrorHandlerExit:
Exit Sub
ErrorHandler:
'
If Err.Number = 3022 Then
Resume Next
Else
Exit Sub
' MsgBox "Error No: " & Err.Number & "; Field missing: end or mun or cep "
' Resume ErrorHandlerExit
End If
End Sub
It should show me 41 pages - 30 labels each page, but it only shows 17 pages - 501 labels. The table really has 1222 records.
This hapens only when I run the report clicking a button in a form that calls a procedure to print the report.
When I run the VB code step by step it works well! It shows all teh 41 pages, 1222 records!
Any help?
My code behind the button:
Private Sub Comando64_Click()
On Error GoTo ErrorHandler
Dim strTable As String
Dim strReport As String
Dim ctl As Access.Control
Dim lst As Access.ListBox
Dim strTrat As String
Dim strNome As String
Dim strEnd As String
Dim strBai As String
Dim strMun As String
Dim strUF As String
Dim strCEP As String
Dim varItem As Variant
Dim intIndex As Integer
Dim intCount As Integer
Dim strWordTemplate As String
Dim strSQL As String
Dim strShortDate As String
Dim strLongDate As String
Dim strDocsPath As String
Dim strTemplatePath As String
Dim intRow As Integer
Dim intRows As Integer
Dim intColumn As Integer
Dim intColumns As Integer
Dim strTest As String
Dim strCountry As String
Dim strDocType As String
Dim strSaveName As String
Dim intSaveNameFail As String
Dim i As String
Dim strSaveNamePath As String
Dim strDocName As String
Dim strDBPath As String
Dim strTextFile As String
Dim strTestFile As String
Dim j As Integer
Dim n As Integer
Dim strGrupo As String
Set lst = Me![lstSelectContacts]
'Select all list items
SelTodosItensList
intColumns = lst.ColumnCount
intRows = lst.ItemsSelected.Count
If intRows = 0 Then
MsgBox "Choose at least one Group"
Me.grupo.SetFocus
Exit Sub
End If
'Delete all records from tblMergeList and creates a new record set
strTable = "tblMergeList"
strSQL = "DELETE tblMergeList.* FROM tblMergeList;"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
Set dbs = CurrentDb
Debug.Print "Opening recordset based on " & strTable
Set rst = dbs.OpenRecordset(strTable, dbOpenTable)
For Each varItem In lst.ItemsSelected
'Record list items in variables
strTrat = Nz(lst.Column(1, varItem))
strNome = Nz(lst.Column(2, varItem))
strEnd = Nz(lst.Column(3, varItem))
strBai = Nz(lst.Column(4, varItem))
strMun = Nz(lst.Column(5, varItem))
strUF = Nz(lst.Column(6, varItem))
strCEP = Nz(lst.Column(7, varItem))
If IsNull(strTrat) Then
strTrat = " "
End If
' 'Record data from vars in a new tblMergeList record
With rst 'com tblMergeList
.AddNew
!trat = strTrat
!nome = strNome
!end = strEnd
!bai = strBai
!mun = strMun
!uf = strUF
!cep = strCEP
.Update
End With
NextContact:
Next varItem
rst.Close
'Deselect all list items
EliminaSelItensList
intColumns = lst.ColumnCount
intRows = lst.ItemsSelected.Count
'Roda rel da etiqueta selecionada
strReport = [cboSelect_etq].[Column](1)
'Run label report in Preview mode
DoCmd.OpenReport strReport, acViewPreview
'Delete all tblMergeList records
DelTodosReg ("tblMergeList")
'Delete all PessoasMala records
DelTodosReg ("PessoasMala")
Me.lstSelectContacts.Requery
Me.qtde = ""
'Initialize var Z
Z = 0
'Deselect all list items
EliminaSelItensList
'Initialize all Combos
Me.grupo = 0
Me.cargo = 0
Me.mun = 0
''Initialize field nome_grupo
Me.nome_grupo = ""
Me.cboSelect_etq = 0
ErrorHandlerExit:
Exit Sub
ErrorHandler:
'
If Err.Number = 3022 Then
Resume Next
Else
Exit Sub
' MsgBox "Error No: " & Err.Number & "; Field missing: end or mun or cep "
' Resume ErrorHandlerExit
End If
End Sub