Search code examples
vbams-accesscmdbarcode

Call Zint from Access VBA


I will be using ZINT as my barcode generator in my Access program. I want to call it by using SHELL command from within Access VBA. My problem is, I can't call ZINT from command prompt. Here is my code.

Private Sub cmdTest_Click()
    Dim strToPrint, strInfoBarcode As String

    strInfoBarcode = "Batch #699"

    strToPrint = "%ProgramFiles%\zint\zint.exe  -o c:\path\699.png -b 58 --vers=10 -d " & strInfoBarcode
    Call Shell("cmd.exe /S /K" & strToPrint, vbMinimizedNoFocus)
End Sub

When i run the above code, the error shows

'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

Could someone shows the right way to call the ZINT program from Access VBA?


Solution

  • Are you missing a space in Program Files? Guessing that's just a typo, but you should be putting quotes around any path with a space.

    Private Sub cmdTest_Click()
        Dim strToPrint, strInfoBarcode As String
    
        strInfoBarcode = "Batch #699"
    
        strToPrint = """%ProgramFiles%\zint\zint.exe""  -o c:\path\699.png -b 58 --vers=10 -d """ & strInfoBarcode & """"
        Call Shell("cmd.exe /S /K " & strToPrint, vbMinimizedNoFocus)
    End Sub
    

    Likewise probably a good idea to also quote the barcode if it might contain any spaces (as shown in the ZINT wiki page on Excel integration: http://zint.org.uk/Excel.aspx).

    EDIT: you were also missing a space after the /K flag, but I don't think you even need to use cmd.exe here.