How to integrate Labeljoy into your data management software
If you want to add label printing to an existing software structure, whether it is a simple Excel file or a corporate ERP system, here are some guidelines for integrating Labeljoy in your existing desktop application setup.
1 – The basics: print shortcut
If you already have created your labels and only need to print them from time to time, it is not necessary to restart Labeljoy every time.
The easiest way to print a Labeljoy file without starting the program is the context menu Print with labeljoy. Right-click on the file and select the second menu item:
Actually this process starts Labeljoy, but just to process the print job. The program then closes automatically.
The method described above requires at least two mouse clicks. However, you can further speed up this operation by creating a Print shortcut.
We need to find the executable program file Labeljoy5.exe. The file path may vary depending on the settings. The default settings should be: C:\Program Files\Labeljoy (or C:\Program Files (x86)\Labeljoy for 64-bit systems).
Note that the .exe extension may not be visible, depending on your Windows settings.
Right click on the Labeljoy program file and select Copy:
Now go to the desktop, right-click on an empty area and select Paste shortcut:
You have now created a shortcut to launch Labeljoy. You can also convert this link into a print shortcut.
Right-click on the newly created shortcut and select Properties:
This is how the shortcut properties window should look like:
We need to edit the text in the Target text box. Add the prefix /P and the full file path and file name of the Labeljoy file to be printed. For example, if the file is on the desktop of the Windows user Henry, our resulting string will be:
“C:\Program files\Labeljoy\Labeljoy5.exe” /P “C:\Users\Henry\Desktop\My label.lpa”
This link instructs Windows to open the file C:\Users\Henry\Desktop\My label.lpa with Labeljoy.
In addition, Labeljoy is instructed to print and close the file.
You now have a 1-click print shortcut for your most used labels.
It might also be useful to rename your shortcut so that its function is easily recognizable.
2 – Printing labels with data connections
Labeljoy enables you to display data from external data sources on the labels, such as Excel files, Access files or professional database systems such as SQL Server, Oracle, or MySQL. Please refer to this video tutorial for more information.
If your labels have to be updated before printing, you have to enable the Update data when this file is loaded or printed option, which you can find in the Group settings form.
This option updates the data whenever the file is loaded or printed. The data is reloaded with the parameters entered during the first connection. In this case, the file C:\Logistic label.xlsx and the worksheet Logistic labels must exist, otherwise the data updating will fail.
This option enables you to print labels with the latest data available. So if the print shortcut we created earlier points to a data connected – auto updating Labeljoy file, all you have to do is click it when new data is available for printing.
IMPORTANT: Labeljoy stores the name of the printer used to print each file. This means that the printer used for 1-click printing will always be the same as the one previously used.
3 – Excel integration with VBA
If the data to be printed is stored in an Excel file, a print shortcut can be created by using the Visual Basic for Application (VBA) programming language within the very same Excel file.
This requires some programming knowledge and knowledge of the VBA environment.
For this we will use a variation of the files created in the GS1-128 tutorial.
We assume that both files are located under the root directory of the C drive, C:\.
Download this file
First, open the Labeljoy file and make sure the option Update data when loading or printing this file is checked, as described in the previous chapter.
If the linked Excel file is stored in a different location than the root of the C: drive, make sure to update the location in Group settings/Data source.
Save the Labeljoy file and close Labeljoy.
From this moment on Labeljoy can remain closed, we just have to take care of the data to be printed.
The Excel file contains a single row of data and a button linked to a VBA Macro:
We now open the Excel file and the VBA editor by pressing ALT + F11. This gives us an insight into the processes in the background:
The modLabelPrinting module contains a single routine named LabelPrint. It is a simple macro that first saves the Excel workbook and then executes the Labeljoy file for printing. This last step is achieved through the use of the ShellExecute Windows API function (more information on the MSDN website).
If the Labeljoy Software integration.lpa file is not located in the root of the C: drive, make sure to change the file path accordingly:
sLabelJoyFileNameAndPath = [Enter the correct file path with quotes here]
When the Save and print button is clicked, the Macro is executed: the Excel file is saved and the Labeljoy file is first updated and then printed.
Try changing the data in the Excel file and click the button to see the resulting printed labels.
4 – Integration in an ERP system
If your company manages its data in an ERP system developed and maintained internally, you can apply the previous approach by writing a corresponding routine using the programming language of your choice.
The only requirement is that Labeljoy is installed on the computer from which the labels are printed.
Following a sample application written in VB.NET (version 2010, Frameworks 2.0 and 3.5). The code should run on a computer with Labeljoy 5 installed.
This example requires basic knowledge of the VB.NET programming language and some knowledge of ADO.NET.
When the application is run the first time, it copies two files that are stored in its resource area:
- Logistic label.mdb. An Access database file containing two tables: The Logistic Label table used to hold the data that will be printed. The ISO3166 table which contains country data identifiers, needed to properly handle the fields Country Code and Country Prefix.
This file is saved in the Data folder under the Labeljoy install directory (i.e. C:\Program files\Labeljoy 5\Data). If the folder doesn’t exist, it will be created.
- Logistic label.lpa. The Labeljoy file to print. This file is stored in the Labeljoy document folder (C:\Users\Username\Documents\Labeljoy). This file contains data associated with the Logistic Label table of the MDB file.
The application consists of a single form that collects the required data for the logistics label:
Once the form contains the data to be printed, the user has to click Print.
The data entered is first validated in the CheckData function. If any incoherence is found, a message box is displayed. Printing will not be performed unless all errors have been resolved. Please find more information in the comments:
Once the data has been validated, it is stored in the Logistic Label table of the MDB file via the Update Data function. As you can see in the code, a Delete statement is always issued before the new data is stored. For this example, we only need one data row in the source table:
Then the label is printed using the ShellExecute Windows API approach:
The Logistic label.lpa file is loaded into Labeljoy and the data is updated by reading the newly entered data from the MDB file. After printing, Labeljoy shuts down.
The data update process is also enabled by using a hidden Labeljoy function: if a Labeljoy file is linked to a data source that is originally stored on the file path of the Labeljoy’s install directory (or any sub-directory), future data updates will always refer to a file path within the install directory, even if it is not exactly the same path as the original file.
For example, suppose you link a Labeljoy file to a data source in C:\Program files\Labeljoy 5\Data where C:\Program files\labeljoy 5 is the install directory. You then move the Labeljoy file and the data file to a different PC. This time, since it is a 64 bit Windows version, the install directory is C:\Program files (x86)\labeljoy 5. You put your data file under C:\Program files (x86)\labeljoy 5\Data. You then open the Labeljoy file and launch data updating: Labeljoy recognize that the original data source was found under [INSTALLDIR]\Data and adapts the path according to the install directory of the current machine.