Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Skipping labels not working

Status
Not open for further replies.

MelissaT

Programmer
May 16, 2002
67
0
0
US
I have the following code from Microsoft's site for skipping used labels when printing mailing labels.

Option Compare Database
Option Explicit

Dim intLabelBlanks As Integer
Dim intLabelCopies As Integer
Dim intBlankCount As Integer
Dim intCopyCount As Integer

'==========================================================
' The following function will cause an inputbox to
' display when the report is run that prompts the user
' for the number of used labels to skip and how many
' copies of each label should be printed.
'===========================================================

Function LabelSetup()
intLabelBlanks = Val(InputBox$("Enter Number of blank labels to skip"))
intLabelCopies = Val(InputBox$("Enter Number of Copies to Print"))
If intLabelBlanks < 0 Then intLabelBlanks = 0
If intLabelCopies < 1 Then intLabelCopies = 1
End Function

'===========================================================
' The following function sets the variables to a zero
'===========================================================

Function LabelInitialize()
intBlankCount = 0
intCopyCount = 0
End Function

'===========================================================
' The following function is the main part of this code
' that allows the labels to print as the user desires.
'===========================================================

Function LabelLayout(R As Report)
If intBlankCount < intLabelBlanks Then
R.NextRecord = False
R.PrintSection = False
intBlankCount = intBlankCount + 1
Else
If intCopyCount < (intLabelCopies - 1) Then
R.NextRecord = False
intCopyCount = intCopyCount + 1
Else
intCopyCount = 0
End If
End If
End Function

It worked great for a while.
But now, it doesn't seem to work anymore. I don't know what has changed. When I preview a report it previews with the skipped labels and the proper number of copies, but as soon as I print it, it loses the skipped labels part and starts at label 1. It does however print the number of copies I requested. I am using Access 2000 on Windows XP and NT machines. Same problem on both. Any ideas?


Melissa
Designing Access databases since 1999
 
Melissa, did you ever come up with a resolution to this problem? I'm experiencing the same problem with an application I just inherited that uses the SkipLabels class. The user selects a position on a grid representing the labels on the page and then the labels are supposed to start printing from that location--the print preview displays perfectly; however, the labels always start in the top left hand corner of the page (position of label1) regardless. Any thoughts?
 
Use this instead. Save this part as a new module

Option Compare Database
Option Explicit
' Label Saver v97.30 from Peter's Software
'
' Allows users to specify a starting label position and a number of copies via input boxes
' when printing labels
'
' This module was created by:
'
' Peter's Software
' ' info@peterssoftware.com
'
' ...with some help from Microsoft Knowledge Base article Q299024
'
' This module is freeware.
'
' I do not require that this header be included in any apps you distribute,
' but would appreciate credit being given in your documentation.
'
' If you find that this product is useful to you, please drop by our web site
' at and sign up on our mailing list so we can
' notify you when new versions of Label Saver and other Access tools become available
'
' Usage:
' LS_Init - from your label report's report header OnFormat event procedure
' (create a label report header if you don't have one already. Set
' the report header section height to 0.)
' LS_ReportOnOpen Me, Cancel - from your label report's OnOpen event procedure, and
' LS_DetailOnPrint Me - from your label report's Detail OnPrint event procedure.
'

'Module variables
Dim iLSBlankRecordsToPrint As Integer
Dim iLSBlankCount As Integer
Dim iLSCopiesToPrint As Integer
Dim iLSCopiesCount As Integer
Sub ls_DetailOnPrint(rpt As Report)
'Print a specified number of blank detail sections.

On Error GoTo ls_DetailOnPrint_err


If iLSBlankCount < iLSBlankRecordsToPrint Then
'Leave a blank detail section without skipping a record
rpt.NextRecord = False
rpt.PrintSection = False
iLSBlankCount = iLSBlankCount + 1
Else
If iLSCopiesCount < iLSCopiesToPrint Then
rpt.NextRecord = False
iLSCopiesCount = iLSCopiesCount + 1
Else
iLSCopiesCount = 1
End If
End If


ls_DetailOnPrint_exit:
Exit Sub
ls_DetailOnPrint_err:
MsgBox "Error in Label Saver subroutine ls_DetailOnPrint - " & Err & " - " & Err.Description
GoTo ls_DetailOnPrint_exit
End Sub

Sub ls_Init()
iLSBlankCount = 0
iLSCopiesCount = 1
End Sub

Sub ls_ReportOnOpen(rpt As Report, ByRef Cancel As Integer)
'Prompts user for a label printing start position, and a number of copies.
'Sets variables for the OnFormat event procedure to handle

Dim iStartLabel As Integer
Dim iCopies As Integer
Dim vResp As Variant


On Error GoTo ls_ReportOnOpen_err

'Prompt user for starting label position
vResp = InputBox("Start at which label?", "Label Saver", 1)
If vResp = "" Then
'Cancel was clicked
Cancel = True
GoTo ls_ReportOnOpen_exit
End If
iStartLabel = CInt(vResp)

'Validation check
If iStartLabel >= 1 And iStartLabel <= 400 Then
Else
MsgBox "Starting label must be between 1 and 400." & vbCrLf & vbCrLf & " Labels/Report cancelled"
Cancel = True
GoTo ls_ReportOnOpen_exit
End If

'Prompt user for number of copies
vResp = InputBox("How many copies of each label?", "Label Saver", 1)
If vResp = "" Then
'Cancel was clicked
Cancel = True
GoTo ls_ReportOnOpen_exit
End If
iCopies = CInt(vResp)

'Validation check
If iCopies < 1 Then
MsgBox "Number of copies must be greater than 0." & vbCrLf & vbCrLf & " Labels/Report cancelled"
Cancel = True
GoTo ls_ReportOnOpen_exit
Else
If iCopies >= 1 And iCopies <= 100 Then
Else
If MsgBox("Are you sure you want to print " & iCopies & " copies of each label?", vbYesNo, "Label Saver") = vbYes Then
Else
MsgBox "Labels/Report cancelled"
Cancel = True
GoTo ls_ReportOnOpen_exit
End If
End If
End If

'Set variables. These are used in the Report Detail OnFormat event procedure
iLSBlankRecordsToPrint = iStartLabel - 1
iLSCopiesToPrint = iCopies

ls_ReportOnOpen_exit:
Exit Sub
ls_ReportOnOpen_err:
MsgBox "Error in Label Saver subroutine ls_ReportOnOpen - " & Err & " - " & Err.Description
GoTo ls_ReportOnOpen_exit
End Sub


Sub ls_ReportOnPage()
'iLSBlankCount = 0
End Sub


On your label report, add the following procedures

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
ls_DetailOnPrint Me
End Sub

Private Sub Report_Open(Cancel As Integer)
ls_ReportOnOpen Me, Cancel 'Label Saver
End Sub

Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As Integer)
ls_Init
End Sub

You have to have the report header and footer showing to run the code, just shrink them up to a zero size if you're not using them.

Melissa
Designing Access databases since 1999
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top