Private Sub cmd_Gen_LabelSet_Click()
On Error GoTo Err_Gen_LabelSet_Click
Dim sSerialBase As String
Dim sModelNumber As String
Dim sSerialNumber As String
Dim sACvolt As String
Dim sACamp As String
Dim sPhase As String
Dim sCnt As String
Dim sHertz As String
Dim sDCVolts As String
Dim stDocName As String
Dim stCriteria As String
Dim iSeqStart As Integer
Dim iSeqEnd As Integer
Dim iLabelNumber As Integer
Dim iTotalLabels As Integer
Dim iNumberOfPages As Integer
Dim iPage As Integer
Dim iFirstLabel As Integer
Dim iLastLabel As Integer
DoCmd.OpenQuery "qryDEL_Old_Gen_Set", acNormal, acEdit
'this section opens up the labelgen database to stuff the label
'information into it
Dim db As DAO.Database
Dim rst As DAO.Recordset
' this section captures the data from the form
sSerialBase = [Base Serial Number]
iSeqStart = [Sequence Start]
iSeqEnd = [Sequence Finish]
Set db = CurrentDb()
Set rst = db.OpenRecordset("tblLabel_gen", dbOpenDynaset)
'this section starts to generate the serial numbers
If IsNull([Hetz]) Then [Hetz] = " "
With rst
For cnt = iSeqStart To iSeqEnd ' sets up the serial number sequence
.AddNew ' opens the table to add new records
' This section Formats the Serial Number so that it has leading zeros
If cnt <= 9 Then sCnt = "00" & cnt
If cnt >= 10 And cnt < 100 Then sCnt = "0" & cnt
If cnt >= 100 Then sCnt = cnt
sSerialNumber = sSerialBase & sCnt ' stores the formated S/N
iLabelNumber = iLabelNumber + 1 ' Stores Label Count
' this section writes the data into the label database
![Label Number] = iLabelNumber
![Serial Number] = sSerialNumber
![Model Number] = [Model Number]
![AC Voltage] = [AC Voltage]
![AC Amps] = [AC Amps]
![Phase] = [Phase]
![Hetz] = [Hetz]
![DC Volts] = [DC Volts]
![Max DC Amps] = [Max DC Amps]
.Update 'without the Update statement it's not going to get stored
Next
End With
' capture the number of labels created
iTotalLabels = iLabelNumber
' see how many sets of reports (pages) must be printed
' each LETTER size page, will print 6 labels custom sized for our application
' the 5/6 addition at the end is to round up to the next full page
' 1 label of 6 (1/6) + (5/6) then the integer makes it a full page number
iNumberOfPages = Int((iTotalLabels / 6) + (5 / 6))
'print the pages
For iPage = 1 To iNumberOfPages
iLastLabel = iPage * 6 ' Define the last label on the page
iFirstLabel = iLastLabel - 6 ' subtract 6 to find the first label
stCriteria = "[Label Number] >" & iFirstLabel & _
"AND [Label Number] <=" & iLastLabel ' set the Filter for each pass
MsgBox "ALERT!!!: ALIGN FOR NEXT LABEL SET" ' Alert the user to reset the label indexing
stDocName = "Label 1"
'DoCmd.OpenReport stDocName, acPreview
DoCmd.OpenReport stDocName, acViewNormal, , stCriteria
Next
MsgBox "COMPLETE! - No More Labels To Print, Thank you and print again soon..."
Exit_Gen_LabelSet_Click:
Exit Sub
Err_Gen_LabelSet_Click:
MsgBox Err.Description
Resume Exit_Gen_LabelSet_Click
End Sub