Results 1 to 9 of 9
  1. #1
    Pawtang's Avatar
    Pawtang is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    91

    Barcode scanning trigger event

    When scanning in data with a barcode via USB input, it's typically interpreted just as keyboard input. I'm hoping to find a way to have Access recognize the input as an event trigger, so that when I have a particular form open, I don't need to have a specific field selected to initiate some code and process the barcode input.



    Furthermore, I would like these fields to function both as combo/text boxes that you can enter data into the traditional way, or to be able to be populated automatically by some VBA logic when an item is scanned. There are two fields per record that would be populated by each scan, with the VBA logic discerning what goes where.

    Is this possible? They do have common textual prefixes ("1PB") that may aid in an event capture but, I don't know of any way to say "if this series of characters is input, launch this event"

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I suppose in the after update event of each control you could have code that tested for that prefix and fired off a function. The code would look like:

    If Left(Me.ControlName, 3) = "1PB" Then
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,522
    add TAB to the scanner control as the last character at scan,
    then the text box event is AFTERUPDATE or LOSTFOCUS. Its what i use.

  4. #4
    Pawtang's Avatar
    Pawtang is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    91
    Quote Originally Posted by pbaldy View Post
    I suppose in the after update event of each control you could have code that tested for that prefix and fired off a function. The code would look like:

    If Left(Me.ControlName, 3) = "1PB" Then
    I could maybe apply this to any KeyPress event or whatever the barcode entry will trigger. I would imagine this wouldn't be enough to impact performance, although it does feel a little clunky to check every possible input.

  5. #5
    Pawtang's Avatar
    Pawtang is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    91
    Quote Originally Posted by ranman256 View Post
    add TAB to the scanner control as the last character at scan,
    then the text box event is AFTERUPDATE or LOSTFOCUS. Its what i use.
    This sounds pretty elegant. I may combine this with a "enable scanning" toggle button to constrain the form input a little further and tighten up what can/can't be active controls while scanning.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    It sounds like you're moving away from

    Quote Originally Posted by Pawtang View Post
    I don't need to have a specific field selected to initiate some code and process the barcode input.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Pawtang's Avatar
    Pawtang is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    91
    Quote Originally Posted by pbaldy View Post
    It sounds like you're moving away from
    I agree, it seems to me that these two proposed methods will necessitate having a control selected initially to be able to capture the event.

    But I think using the "enable scanning" feature could "turn on" a global capture, making it easier to code from an "any input is barcode input" perspective and then just chop up all the incoming data and put it into the right boxes based on prefixes, rather then retroactively checking to see if the data entered is prefixed by specific text or not.

    So maybe combining these methods is not necessary, maybe its a question of which works better overall for this use case.

  8. #8
    Pawtang's Avatar
    Pawtang is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    91
    I have written some code that successfully handles 2 dimensional barcodes, where all of the data is entered in one line. This assigns each piece of the data to the correct field (two fields total) and then jumps to next record to be ready to accept next scan:

    Code:
    Option Compare Database
    
    Private Sub btnToggleScanning_Click()
        newLineFocus
    End Sub
    
    
    Public Sub cboPartNumber_AfterUpdate()
        'Scanning turned ON?
        If btnToggleScanning = True Then
            Dim barString As String
            Dim partStr As String
            Dim dateStr As String
            Dim barType As String
            barString = cboPartNumber
            
            'Case 1D barcodes
                If InStr(barString, "31P") = 0 Then
                    'barType = linear
                    If InStr(barString, "1P") = 0 Then
                    'dateStr = Mid(barString, 2, 10)
                    Else
                    'partStr = Mid(barString, 3, 20)
                    'Me!dateCode.SetFocus
                    End If
                Else
                'Case 2D Barcode
                partStr = Mid(barString, InStr(barString, "31P") + 3, InStr(barString, "+S") - InStr(barString, "31P") - 3)
                dateStr = Right(barString, (Len(barString) - InStr(barString, "+S")) - 1)
            End If
            
            'Write data
            Me!cboPartNumber = partStr
            Me!dateCode = dateStr
            'Next record
            newLineFocus
        'Contain scanning
        End If
    End Sub
    
    
    Function newLineFocus()
        If btnToggleScanning = True Then
        DoCmd.GoToRecord , , acNewRec
        Me!cboPartNumber.SetFocus
        End If
    End Function
    The problem I'm facing now is handling 1D barcode scans, where I need to wait for the second piece of information to be scanned in. You can see where I commented out the 1D section. Part of the problem is that this occurs after update of the cboPartNumber control... I wonder if I need to split the handling up at a higher level, and then call one of two field assignment functions based on initial criteria. Any ideas? If I can handle this neatly within this single function, that would be ideal. But I don't know how to make it wait for a second input.

  9. #9
    Pawtang's Avatar
    Pawtang is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    91
    I'm continuing to update this thread for posterities sake; maybe someone will come looking for some messy barcode parsing code.

    I've managed to handle both 2 dimensional and 1 dimensional scans with this module. The fact that I'm handling two different fields and also checking if the scan is 1d or 2d makes this a little confusingly recursive, but it does work. It doesn't account for every possible way a user could break the input yet, but hopefully it'll get there. Here's how I did it:

    Code:
    Option Compare Database
    
    Private Sub btnToggleScanning_Click()
        newLineFocus
    End Sub
    
    
    
    
    Private Sub cboPartNumber_AfterUpdate()
        'Scanning turned ON?
        If btnToggleScanning = True Then
            Dim barStr As String
            barStr = cboPartNumber
                If InStr(barStr, "31P") = 0 Then
                    linearScan barStr
                    Else
                    QRScan barStr
            End If
        End If
    End Sub
    
    
    Private Sub QRScan(barStr As String)
        Dim partStr As String
        Dim dateStr As String
        partStr = Mid(barStr, InStr(barStr, "31P") + 3, InStr(barStr, "+S") - InStr(barStr, "31P") - 3)
        dateStr = Right(barStr, (Len(barStr) - InStr(barStr, "+S")) - 1)
        Me!cboPartNumber = partStr
        Me!dateCode = dateStr
        newLineFocus
    End Sub
    
    
    Private Sub linearScan(barStr As String)
        Dim partStr As String
        Dim dateStr As String
        If InStr(barStr, "1P") = 0 Then
        'If not part number, then date
                    dateStr = Mid(barStr, 2, 10) 'Set date variable
                    Me!dateCode = dateStr 'Write data
                    Me!cboPartNumber = ""
                    Me!cboPartNumber.SetFocus
                Else
                    partStr = Mid(barStr, 3, 20)
                    Me!cboPartNumber = partStr
                        If Len(dateStr) = 0 Then
                            Me!dateCode.SetFocus
                        Else
                            newLineFocus
                        End If
                End If
    End Sub
    
    
    Private Sub dateCode_AfterUpdate()
    If btnToggleScanning = True Then
        Dim dateStr As String
        Dim barStr As String
            barStr = dateCode
                If InStr(barStr, "S") = 1 Then
                        dateStr = Mid(barStr, 2, 10) 'Set date variable
                        Me!dateCode = dateStr 'Write data
                        newLineFocus
                    Else
                        Me!dateCode = "" 'Write data
                        Me!dateCode.SetFocus
                    
            End If
        End If
    End Sub
    
    
    
    
    Private Sub newLineFocus()
        If btnToggleScanning = True Then
        DoCmd.GoToRecord , , acNewRec
        Me!cboPartNumber.SetFocus
        End If
    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Barcode Scanning
    By RandyH in forum Programming
    Replies: 16
    Last Post: 12-23-2020, 03:34 AM
  2. check barcode serial number before scanning
    By hullstorage in forum Programming
    Replies: 1
    Last Post: 07-14-2020, 06:33 AM
  3. Use barcode to trigger click event.
    By Ziggy in forum Forms
    Replies: 13
    Last Post: 07-03-2019, 03:22 AM
  4. Replies: 5
    Last Post: 05-16-2019, 09:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums