Customisation of the Access macros

The PBarcode macro operates when a table is displayed in datasheet view, takes the barcode data from selected cells (which must be Text cells) and pastes the barcode images into the adjacent cells (which must be OLEObect cells). Navigation and pasting are controlled by sending keystrokes to the table. TAB keys move the cursor around and the ^v (Control + V) initiates the pasting of the image.

    Set tbl = Screen.ActiveDatasheet
    i = tbl.SelTop
    j = tbl.SelLeft
    k = tbl.SelHeight
    If k > 1 Then n = k - 1 Else n = 1
    SendKeys "{TAB}", True
    SendKeys "+{TAB}", True
For i = 1 To n
    Set CurrentControl = Screen.ActiveControl
    If (IsEmpty(CurrentControl.Text) Or IsNull(CurrentControl.Text) Or CurrentControl.Text = "") Then
    errorcode = 9
        GoTo done
        End If

    BarcodeString = CurrentControl.Text
    k = 0
    errorcode = BarCodew(ByVal BarcodeString, k)
    If (errorcode = 0) Then
    ' these keys paste the barcode image into the adjacent cell
        SendKeys "{TAB}", True
        SendKeys "{DEL}", True
        SendKeys "^v", True
    ElseIf errorcode = 1 Then
        MsgBox "Wrong number of characters in barcode"
    ElseIf errorcode = 4 Then
        MsgBox "Illegal character in barcode data"
    Else
        MsgBox "Error in barcode data"
    End If

    ' these keys move to the cell below for the next source
    SendKeys "+{TAB}", True
    SendKeys "{DOWN}", True
Next i
done:

It is generally not necessary to edit this macro because there is no significance in the order of columns in datasheet view.

The FBarcode macro uses named fields in a named table, by default taking the barcode data from a field named BarcodeSource in Table1 and placing the font-based barcode into a field named BarcodeFont. Any of these names may be changed simply by editing the macro code:

Set MyDB = CurrentDb()
Set dset = MyDB.OpenRecordset("Table1")
'
' The rest just cycles down the table taking the source text from a field called BarcodeSource
' and placing the output in a field called BarcodeFont
'
' Edit as required to change fieldnames
'
dset.MoveFirst
Do Until dset.EOF
    dset.Edit
    St$ = dset!BarcodeSource
    n = Len(St$)
    Out$ = String(255, " ")
    x = BarCodewF(ByVal St$, n, ByVal Out$, ByVal foname$, foht)
   If (x > 0) Then
        dset!BarcodeFont = Out$
        dset.UPDATE
        End If
    dset.MoveNext
    Loop
dset.Close

More:

Active Barcode in Access