Example of Creating Template Files with Access VBA
Create a Template File (Label Layout File)
-
1.
The following is a description using a fixed asset list created with Access.
- 2. Create a form with a name of "Print Label" and add the Print Label button to it.
-
3.
Write the following code in the event procedure of the Print Label button.
Private Sub Label Print_Click() 'Create a b-PAC object Dim ObjDoc As bpac.Document Set ObjDoc = CreateObject("bpac.Document") 'Open a template file created with P-touch Editor '(Put this Access file and the template file in the same folder) Dim bRet As Boolean bRet = ObjDoc.Open(CurrentProject.Path & "\asset.lbx" If (bRet <> False) Then 'Assign data to the text object of "Fixed asset name" ObjDoc.GetObject("Name").Text = Me![Fixed asset name].Value 'Assign data to the text object of "Management section" ObjDoc.GetObject("Section").Text = Me![Management section].Value 'Assign data to the text object of "Identification No." ObjDoc.GetObject("Number").Text = Me![Identification No].Value 'Assign data to the barcode object ObjDoc.GetObject("QRCode1").Text = Me![Identification No].Value 'Print ObjDoc.StartPrint "DocumentName", bpoAutoCut ObjDoc.PrintOut 1, bpoAutoCut ObjDoc.EndPrint 'Print ObjDoc.StartPrint "DocumentName", bpoAutoCut ObjDoc.PrintOut 1, bpoAutoCut ObjDoc.EndPrint End If 'Free the b-PAC object Set ObjDoc = Nothing Exit_Print_Click: Exit Sub Err_Print_Click: MsgBox Err.Description Resume Exit_Print_Click End Sub
Note
- You can also change an image object and configure the font settings.
- For methods available from b-PAC, refer to the b-PAC SDK documentation.
- 4. Exit Design Mode of the form and, with the Print Label form, open the data to print before clicking the Print Label button.
Labels are printed with values of cells of selected rows while the label layout file created with P-touch Editor is used as the template.
Download
FAQ
For Developers
-
Choose from Purposes
Label printing, printer setup and management information.
-
b-PAC
Information on application development tools for Windows
-
Mobile SDK
Information on application development tools for mobile terminals
-
Command Reference
Information on control command reference for label printers and mobile printers
-
Versatile software
Information on versatile software provided by Brother
-
Choose from Models
Introduction of Brother tools applicable to your model
-
Video Library
Videos showing how to use SDK and other information
-
Contact Us
Fill out the contact us form if you have questions about Brother developer tool.