VBA barcode code generator not working (1 Viewer)

Alhakeem1977

Registered User.
Local time
Today, 07:57
Joined
Jun 24, 2017
Messages
308
Hi all,
I used to generate a barcode font in MS Access 2010 normally with no issues even with the same printer, but when our company changed my desktop PC and upgraded to Windows 10 and MS Access to 2013 it's no more working I do not know how to fix this issue.

I tried the same application at home on my laptop which has Windows 10 and MS Access 2013 it works normally

Any help or suggestion is highly appreciated, thanks in advance!

Below is the VBA code and at the beginning, comments illustrate how to implement the barcode:
Code:
' mod_BarCode_Generator_Code39
'
' Barcode Generator for Code 3 of 9, Code 39, and Mil-spec Logmars.
'
' version 2.0 (updated for MsAccess 97)
'
' (c) 1993-1999 James Isle Mercanti, Cocoa Beach, FL 32931  USA
' Permission granted for public use and royalty-free distribution.
' No mention of source or credits is required. All rights reserved.
'
' TO USE THIS CODE:
'
'   1 - Create Report with a TextBox control. (example named Barcode)
'       Make sure the Visible property is set to "No".
'   2 - Set On-Print property of section to [Event Procedure]
'       by clicking on the [...] and selecting "Code Builder"
'   3 - Confirm that the following code matches yours...
'
'      Sub Detail1_Print(Cancel As Integer, PrintCount As Integer)
'
'         Result = Barcode_39(Barcode, Me)
'
'      End Sub
'
'   4 - NOTE: The name of the section is "Detail1" for example only!
'       Your section might show a different name. Ditto for "Barcode".
'
'   5 - NOTE: To use on sub-forms, the Report name should be hard-coded
'       into the function. i.e. Rpt = Reports!MainForm!SubForm.Report.
'       The easy method is to just avoid using sub-forms and sub-reports.
'

Function Barcode_39(Ctrl As Control, rpt As Report)
    On Error GoTo ErrorTrap_BarCode39

    Dim Nbar As Single, Wbar As Single, Qbar As Single, Nextbar As Single
    Dim CountX As Single, CountY As Single, CountR As Single
    Dim Parts As Single, Pix As Single, Color As Long, BarCodePlus As Variant
    Dim Stripes As String, BarType As String, Barcode As String
    Dim Mx As Single, my As Single, Sx As Single, Sy As Single
    Const White = 16777215: Const Black = 0
    Const Nratio = 20, Wratio = 55, Qratio = 35

    'Get control size and location properties.
    Sx = Ctrl.Left: Sy = Ctrl.Top: Mx = Ctrl.Width: my = Ctrl.Height

    'Set handle on control.
    Barcode = Ctrl

    'Calculate actual and relative pixels values.
    Parts = (Len(Barcode) + 2) * ((6 * Nratio) + (3 * Wratio) + (1 * Qratio))
    Pix = (Mx / Parts):
    Nbar = (20 * Pix): Wbar = (55 * Pix): Qbar = (35 * Pix)

    'Initialize bar index and color.
    Nextbar = Sx
    Color = White

    'Pad each end of string with start/stop characters.
    BarCodePlus = "*" & UCase(Barcode) & "*"

    'Walk through each character of the barcode contents.
    For CountX = 1 To Len(BarCodePlus)
        'Get Barcode 1/0 string for indexed character.
        Stripes = MD_BC39(Mid$(BarCodePlus, CountX, 1))
        For CountY = 1 To 9
            'For each 1/0, draw a wide/narrow bar.
            BarType = Mid$(Stripes, CountY, 1)

            'Toggle the color (black/white).
            If Color = White Then Color = Black Else Color = White
            Select Case BarType
                Case "1"
                    'Draw a wide bar.
                    rpt.Line (Nextbar, Sy)-Step(Wbar, my), Color, BF
                    Nextbar = Nextbar + Wbar
                Case "0"
                    'Draw a narrow bar.
                    rpt.Line (Nextbar, Sy)-Step(Nbar, my), Color, BF
                    Nextbar = Nextbar + Nbar
            End Select
        Next CountY

        'Toggle the color (black/white).
        If Color = White Then Color = Black Else Color = White

        'Draw intermediate "quiet" bar.
        rpt.Line (Nextbar, Sy)-Step(Qbar, my), Color, BF
        Nextbar = Nextbar + Qbar
    Next CountX

Exit_BarCode39:
    Exit Function

ErrorTrap_BarCode39:
    Resume Exit_BarCode39
End Function

Function MD_BC39(CharCode As String) As String
    On Error GoTo ErrorTrap_BC39

    ReDim BC39(90)

    BC39(32) = "011000100" ' space
    BC39(36) = "010101000" ' $
    BC39(37) = "000101010" ' %
    BC39(42) = "010010100" ' * Start/Stop
    BC39(43) = "010001010" ' +
    BC39(45) = "010000101" ' |
    BC39(46) = "110000100" ' .
    BC39(47) = "010100010" ' /
    BC39(48) = "000110100" ' 0
    BC39(49) = "100100001" ' 1
    BC39(50) = "001100001" ' 2
    BC39(51) = "101100000" ' 3
    BC39(52) = "000110001" ' 4
    BC39(53) = "100110000" ' 5
    BC39(54) = "001110000" ' 6
    BC39(55) = "000100101" ' 7
    BC39(56) = "100100100" ' 8
    BC39(57) = "001100100" ' 9
    BC39(65) = "100001001" ' A
    BC39(66) = "001001001" ' B
    BC39(67) = "101001000" ' C
    BC39(68) = "000011001" ' D
    BC39(69) = "100011000" ' E
    BC39(70) = "001011000" ' F
    BC39(71) = "000001101" ' G
    BC39(72) = "100001100" ' H
    BC39(73) = "001001100" ' I
    BC39(74) = "000011100" ' J
    BC39(75) = "100000011" ' K
    BC39(76) = "001000011" ' L
    BC39(77) = "101000010" ' M
    BC39(78) = "000010011" ' N
    BC39(79) = "100010010" ' O
    BC39(80) = "001010010" ' P
    BC39(81) = "000000111" ' Q
    BC39(82) = "100000110" ' R
    BC39(83) = "001000110" ' S
    BC39(84) = "000010110" ' T
    BC39(85) = "110000001" ' U
    BC39(86) = "011000001" ' V
    BC39(87) = "111000000" ' W
    BC39(88) = "010010001" ' X
    BC39(89) = "110010000" ' Y
    BC39(90) = "011010000" ' Z

    MD_BC39 = BC39(Asc(CharCode))

Exit_BC39:
    Exit Function

ErrorTrap_BC39:
    MD_BC39 = ""

    Resume Exit_BC39
End Function
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 21:57
Joined
Oct 29, 2018
Messages
21,358
Hi. Check your available fonts. Maybe IT forgot to reinstall the one you were using.
 

Alhakeem1977

Registered User.
Local time
Today, 07:57
Joined
Jun 24, 2017
Messages
308
Hellow, thanks theDBguy for usual prompt responses, actually the VBA barcode generates the barcode independently it does require any font
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 21:57
Joined
Oct 29, 2018
Messages
21,358
Hellow, thanks theDBguy for usual prompt responses, actually the VBA barcode generates the barcode independently it does require any font
I see. Can you compile the code without any errors? Just curious if you have any missing references.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 04:57
Joined
Jul 9, 2003
Messages
16,245
I note from problems with converting macros into VBA Code that sometimes you MUST include the Value property when referring to to a controls contents.

See my Blog HERE:-

Use "Value" or Not?

You cannot Always omit “Value”

I'm wondering if this is what is happening here.

I would suggest you make the following changes to the code and then see if it works.

Change THIS:-
Code:
    'Set handle on control.
    Barcode = Ctrl

To THIS:-
Code:
    'Set handle on control.
    Barcode = Ctrl.Value

In the meantime I will set up a test dB and see if I can reproduce the error...
 

Alhakeem1977

Registered User.
Local time
Today, 07:57
Joined
Jun 24, 2017
Messages
308
I note from problems with converting macros into VBA Code that sometimes you MUST include the Value property when referring to to a controls contents.

See my Blog HERE:-

Use "Value" or Not?

You cannot Always omit “Value”

I'm wondering if this is what is happening here.

I would suggest you make the following changes to the code and then see if it works.

Change THIS:-
Code:
    'Set handle on control.
    Barcode = Ctrl

To THIS:-
Code:
    'Set handle on control.
    Barcode = Ctrl.Value

In the meantime I will set up a test dB and see if I can reproduce the error...

Thanks for your response, I will try it at the office and I will let you know with the result.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 04:57
Joined
Jul 9, 2003
Messages
16,245
I would be much appreciated to do so.

I'm a bit stuck at the moment because the function passes the value back to "Result" which is undefined.

I tried replacing "result" so that it would pass it back into the function signature but that didn't work so I'm scratching my head at the moment.

if there's any more information you can provide on the origin of the code that might be helpful....
 

Minty

AWF VIP
Local time
Today, 04:57
Joined
Jul 26, 2013
Messages
10,355
I hate to be late to the party but have you considered loading a free barcode font?
 

Alhakeem1977

Registered User.
Local time
Today, 07:57
Joined
Jun 24, 2017
Messages
308
What's the "something else?"
I meant by "something else" that might be system accountability with this code because it's very old.
Unfortunately, I left my office I will check Uncle Gizmo's suggestion tomorrow and let you know the result.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 21:57
Joined
Oct 29, 2018
Messages
21,358
I meant by "something else" that might be system accountability with this code because it's very old.
Unfortunately, I left my office I will check Uncle Gizmo's suggestion tomorrow and let you know the result.
Okay, thanks for the clarification.
 

Alhakeem1977

Registered User.
Local time
Today, 07:57
Joined
Jun 24, 2017
Messages
308
I hate to be late to the party but have you considered loading a free barcode font?
Your suggestion can work normally, but in this case, I have to install the front to all users machines otherwise this code can generate the barcode without any burthen for new joiners.

Thank you so much.
 

Alhakeem1977

Registered User.
Local time
Today, 07:57
Joined
Jun 24, 2017
Messages
308
I'm a bit stuck at the moment because the function passes the value back to "Result" which is undefined.

I tried replacing "result" so that it would pass it back into the function signature but that didn't work so I'm scratching my head at the moment.

if there's any more information you can provide on the origin of the code that might be helpful....

Thanks for intuitive, if you follow the comment which is mentioned at the beginning of the code you might generate the barcode.
Unfortunately, I left my office I will check your suggestion to add:
Barcode = Ctrl.Value
tomorrow and let you know the result.
 

Gasman

Enthusiastic Amateur
Local time
Today, 04:57
Joined
Sep 21, 2011
Messages
14,048
That code works fine for me?, at least it produces a bar code?

Win10 32bit, Access 2007

Me.txtBarcode = 12554433

1588534487476.png
 

Alhakeem1977

Registered User.
Local time
Today, 07:57
Joined
Jun 24, 2017
Messages
308
That code works fine for me?, at least it produces a bar code?

Win10 32bit, Access 2007

Me.txtBarcode = 12554433

View attachment 81782
Thank you, it works at my home laptop with:
Win10 32bit, Access 2013

But my concern is as I stated above, it doesn't work at my office with:
Win10 64bit, Access 2013

Hopefully the Uncle Gizmo's suggestion will work tomorrow.
 

Gasman

Enthusiastic Amateur
Local time
Today, 04:57
Joined
Sep 21, 2011
Messages
14,048
Thank you, it works at my home laptop with:
Win10 32bit, Access 2013

But my concern is as I stated above, it doesn't work at my office with:
Win10 64bit, Access 2013

Hopefully the Uncle Gizmo's suggestion will work tomorrow.
I must have missed something, as I saw no mention of a macro?, plus the code is (c) 1993-1999. Did we even have Access macros then?
I can also get access to a Win10 64bit Access 2007 laptop tomorrow.?
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 04:57
Joined
Jul 9, 2003
Messages
16,245
Hopefully the Uncle Gizmo's suggestion will work tomorrow.

Unfortunately I've got 64-bit, and it doesn't work for me with the "Value" .... I've got a couple of other things to try.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 12:57
Joined
May 7, 2009
Messages
19,169
you do not need to Catch the return value from the function.
the function will only Work on Report and in Print view only

on report view, add a (un)Bound Textbox. set its Visible property to No.
on the Detail's Print event:

=Barcode_39([theHiddenTextboxName], [Report])

save the report and view in Print Preview.
 

Attachments

  • barcode39.zip
    31.6 KB · Views: 663

Users who are viewing this thread

Top Bottom