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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Report will not print

Status
Not open for further replies.

lewatkin

Programmer
Mar 8, 2002
91
US
Hi,

I need help bad!!

I have the need to be able to print a different number of different labels. Example, Label1 - 2 copies, Label2 - 4 copies, Label3 - 1 copy etc. etc. The attached code loops through the recordset and does just that. It allows the user to start printing labels anywhere on the page - to use up partial sheets of labels. I got the code from the MKB then adjusted it to what I need. When you print preview the report, it works beautiful. When you attempt to print - it will not send the file to the printer and therefore will not print. I removed the line that says 'rec.MoveNext' and the report will print - except it has the wrong number of labels. The information for the labels are kept in a table with the field QTY as the number of labels needed. Can anyone PLEASE help me?!? I think I have a minor concussion from beating my head on the desk.

Thank you in advance for any assistance

Lee
'==========================================================
' This declares all variables with a Public Scope so that
' all values are kept while the report is open.
'==========================================================
Option Compare Database
Option Explicit

Dim LabelBlanks&
Dim LabelCopies&
Dim BlankCount&
Dim CopyCount&
Dim i As Integer
Dim db As Database
Dim rec As Recordset

'==========================================================
' The following function will cause an input box to
' display when the report is run that prompts the user
' for the number of used labels to skip.
'===========================================================

Function LabelSetup()

LabelBlanks& = Val(InputBox$("Enter Number of blank labels to skip. Maximum is 29."))


If LabelBlanks& > 0 Then
MsgBox "Please make sure that your sheet of labels is in the printer " _
& "with the first blank label in the upper left hand corner.", _
vbInformation, "Label Setup!!"
End If
If LabelBlanks& < 0 Then LabelBlanks& = 0

End Function
'===========================================================
' The following function sets all variables to a zero when
' the report initializes.
'===========================================================
Function LabelInitialize()
BlankCount& = 0
i = 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 IsNull(rec(&quot;QTY&quot;)) Then
CopyCount& = 1
End If
i = i + 1 'this counts number of labels on the report (max 30)

If BlankCount& < LabelBlanks& Then
R.NextRecord = False
R.PrintSection = False
BlankCount& = BlankCount& + 1

Else

If i = 31 Then 'if 31, then reset i to 0, exit and recall for next
'page of report. BlankCount& is kept because of
'public scope, therefore no labels are skipped on the
'remaining pages of the report
i = 0
Exit Function
End If
If CopyCount& < (rec(&quot;QTY&quot;) - 1) Then
R.NextRecord = False
CopyCount& = CopyCount& + 1
Else
CopyCount& = 0
rec.MoveNext
End If
End If
End Function

Function LabelByDate()

DoCmd.SetWarnings False
DoCmd.OpenQuery &quot;Label By Date&quot;, acViewPreview
Set db = CurrentDb()
Set rec = db.OpenRecordset(&quot;zLabelByDate&quot;)
DoCmd.OpenReport &quot;Label By Date&quot;
DoCmd.SetWarnings True

End Function

Function GenericLabelReport()

Set db = CurrentDb()
Set rec = db.OpenRecordset(&quot;OLE 044&quot;)
DoCmd.OpenReport &quot;Generic Label Maker&quot;, acViewPreview

End Function

Function LabelByMonth()

DoCmd.SetWarnings False
DoCmd.OpenQuery &quot;Label By Month&quot;
Set db = CurrentDb()
Set rec = db.OpenRecordset(&quot;zLabelByMonth&quot;)
DoCmd.OpenReport &quot;Label By Month&quot;, acViewPreview
DoCmd.SetWarnings True

End Function

Function RClose()

rec.Close
End Function
 
I have only looked through this quickly and am not an expert by any means but it seems to me that you are referenceing the field QTY in rec before the recordset has been opened? So the result will always be nothing. Maybe..
 
The three functions at the bottom open the recordset. They set the recordset depending on which report you want to see. Thanks though.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top