StrokeScribe1.Alphabet = CODE39 ‘This code will output CODE 39 barcodes

Printer.ScaleMode = vbMillimeters

bar_w = 35 ‘Barcode width, 35mm
bar_h = 20 ‘Barcode height, 20mm
page_w = 40 ‘Page width
page_h = 45 ‘Page height

Dim ID, Barcode, Artikel, kode_warna, Warna, Ukuran

ID = rs_barcode.Fields(“id”)
Barcode = rs_barcode.Fields(“barcode”)

Dim rstSearch As ADODB.Recordset
Set rstSearch = New ADODB.Recordset
gString = “SELECT * FROM barcode_global WHERE id=” & ID
‘MsgBox gString
Set rstSearch = cn.Execute(gString)
Do While Not rstSearch.EOF
Artikel = rstSearch(“artikel”)
kode_warna = rstSearch(“kode_warna”)
Ukuran = rstSearch(“ukuran”)
rstSearch.MoveNext
Loop

‘get warna from master warna
gString = “SELECT * FROM warna WHERE kode_warna='” & kode_warna & “‘”
‘MsgBox gString
Set rstSearch = cn.Execute(gString)
Do While Not rstSearch.EOF
Warna = rstSearch(“jenis_warna”)
rstSearch.MoveNext
Loop

Dim TopMargin, LeftMargin, LineSpacing, BulanCetak
TopMargin = 3
LeftMargin = 14
LineSpacing = 6

For i = 1 To 1 ‘We will print 1 labels

StrokeScribe1.text = Barcode
Set pic = StrokeScribe1.GetPictureHandle(EMF, bar_w, bar_h) ‘Returns a handle to a barcode image in EMF format

If StrokeScribe1.Error > 0 Then ‘In case of an error we will show the message and cancel printing
MsgBox StrokeScribe1.ErrorDescription
Printer.KillDoc
Exit Sub
End If

Printer.CurrentX = 0 ‘A text label will appear at the top-left corner of the page
Printer.CurrentY = 0

‘set default font
Printer.Font = “Arial Black”
Printer.FontBold = True
Printer.FontItalic = False
Printer.FontSize = 20 ‘A small, 6-point font

‘printing Artikel
txt_w = Printer.TextWidth(Artikel)
txt_h = Printer.TextHeight(Artikel)

If Len(Artikel) > 6 Then
Printer.Font = “Arial Narrow”
Printer.FontBold = True
Printer.FontItalic = False
Printer.FontSize = 20 ‘A small, 6-point font
End If
Printer.CurrentX = 5 + LeftMargin
Printer.CurrentY = 1 * LineSpacing – 5
Printer.Print Artikel

Printer.Font = “Arial Black”
Printer.FontBold = True
Printer.FontItalic = False
Printer.FontSize = 20 ‘A small, 6-point font

‘printing warna
txt_w = Printer.TextWidth(Warna)
txt_h = Printer.TextHeight(Warna)
Printer.CurrentX = 5 + LeftMargin
Printer.CurrentY = 2 * LineSpacing – 5
Printer.Print Warna

‘printing Ukuran & Bulan Cetak
txt_w = Printer.TextWidth(Ukuran)
txt_h = Printer.TextHeight(Ukuran)
Printer.CurrentX = 5 + LeftMargin
Printer.CurrentY = 3 * LineSpacing – 5
Printer.FontSize = 20 ‘A small, 6-point font
Printer.Print Ukuran

Select Case Month(Now)
Case 1
BulanCetak = “A”
Case 2
BulanCetak = “B”
Case 3
BulanCetak = “C”
Case 4
BulanCetak = “D”
Case 5
BulanCetak = “E”
Case 6
BulanCetak = “F”
Case 7
BulanCetak = “G”
Case 8
BulanCetak = “H”
Case 9
BulanCetak = “I”
Case 10
BulanCetak = “J”
Case 11
BulanCetak = “K”
Case 12
BulanCetak = “L”
End Select

Select Case Year(Now)
Case 2016
BulanCetak = BulanCetak & “P”
Case 2017
BulanCetak = BulanCetak & “Q”
Case 2018
BulanCetak = BulanCetak & “R”
Case 2019
BulanCetak = BulanCetak & “S”
Case 2020
BulanCetak = BulanCetak & “T”
End Select

Printer.FontItalic = True
Printer.CurrentX = 20 + LeftMargin
Printer.CurrentY = 3 * LineSpacing – 3
Printer.FontSize = 14 ‘A small, 6-point font
Printer.Print BulanCetak

‘printing barcode
Printer.PaintPicture pic, (page_w / 2 – bar_w / 2) + LeftMargin, (page_h – bar_h) – 3 ‘The barcode image is centered on the page

‘Printer.NewPage ‘When printing on label printers like Zebra, we need to print each label on a new page
Next

Printer.EndDoc ‘The printer starts printing the job

‘insert print log
Dim rstBarcodePrint As ADODB.Recordset
Set rstBarcodePrint = New ADODB.Recordset
gString = “INSERT INTO barcode_print_single (barcode, username, printed) VALUES (‘” & Barcode & “‘,'” & user_name & “‘,'” & Format(Now, “yyyy-mm-dd h:mm:ss”) & “‘)”
‘MsgBox gString
Set rstBarcodePrint = cn.Execute(gString)

Tags: