Results 1 to 6 of 6
  1. #1
    kamathmanoj is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    May 2019
    Posts
    41

    Scanning a Barcode > Remove Leading alphabets + use them to verify it is the right barcode

    Hi Everyone,



    I am trying to scan a bar code that reads Z0.0270 (as an example) to a numeric field. I need to check if the leading character is indeed a "Z" and then remove it. If it is not a "Z", I want to show the user that its the wrong bar code.
    I do not want to modify the scanner to scan only numeric values as that would not allow me to verify which bar code is being scanned.

    I have tried every property on the tab to set and event procedure to check the contents of the form field but all have failed so far.

    I have tried this code in each event shown in the picture (below the code) but Access always gets to the contents before my code does and returns the error "The value you entered isn't valid for this field."

    'Check if scanned code has the correct leading characters
    If Left(Me![contentCValue], 2) <> "ZC" Then
    MsgBox ("Please scan the Carbon barcode.")
    Else
    Me![contentCValue] = Mid(Me![contentCValue], 3, Len(Me![contentCValue] - 2))
    MsgBox (Me![contentCValue])
    End If

    Click image for larger version. 

Name:	123.PNG 
Views:	17 
Size:	11.8 KB 
ID:	38418

    Can someone please help me? Desperate.

    Regards,
    Rick

  2. #2
    kamathmanoj is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    May 2019
    Posts
    41
    Update!
    I worked around this by using a unbound text box that will receive the scanned bar code and ran the function on it.

    Here is the code:
    Private Sub Text133_AfterUpdate() ' This is the unbound text box receiving the scan
    'Check if scanned code has the correct leading characters
    If Left(Me![Text133], 2) <> "ZC" Then
    MsgBox ("Please scan the Carbon barcode.")
    Else
    Me.[contentCValue] = Int(Mid(Me![Text133], 3, Len(Me![Text133] - 2)))
    MsgBox (Me.[contentCValue])
    End If
    End Sub

    New issue: the form field is not updating from the Me.[contentCValue] = Int(Mid(Me![Text133], 3, Len(Me![Text133] - 2))) code. Neither is the message box showing up.

    Please help!
    Me.[contentCValue] = Int(Mid(Me![Text133], 3, Len(Me![Text133] - 2)))

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Use BeforeUpdate event to do data validation and cancel the input if not valid.

    Use AfterUpdate event to set value of field.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    kamathmanoj is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    May 2019
    Posts
    41
    Hi June7,

    Yes I have done that but its now returning a data type mismatch when I use this code:
    ********
    Dim CContentValue
    CContentValue = Me![Text133]
    If Left(CContentValue, 2) <> "ZC" Then
    MsgBox ("Please scan the Carbon barcode.")
    Else
    MsgBox (VarType(CContentValue))
    CContentValue = Mid(Me![Text133], 3, Len(Me![Text133] - 2))
    MsgBox (CContentValue)
    End If
    *******

    The message box works to show me that the Left() function works on the string.
    I used Vartype to find out if the CContentValue is a string and it returned 8 as the result which meant CContentValue is a string.

    However, it is not accepting the Mid() into the CContentValue and says it is a data type mismatch????

    Regards,
    Manoj

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    I am not seeing two events coding.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    Here's some tips that may or may not apply here:
    Dim CContentValue - always type your variables. For the benefit of others who may follow you, type it explicitly and eliminate uncertainty. When I read that, I wonder if you know it's a variant or not - especially when you seem to see a need to verify with a message box. Further, your test will return a value for type text if the control contains a string (including zero length string; i.e. "") but variant if it's Null.
    Me![Text133] No, Me.[Text133]. If a control with that name doesn't exist on the form, you won't catch it in a code compile - no error until a run time reference to it occurs. A bad way to catch mis-spelled names.
    Mid(Me![Text133], 3, Len(Me![Text133] - 2)) I read this as you want everything after the first 2 characters. If you don't specify a length for Mid, you get everything after the start point, so no need to worry about calculating the length: Mid(Me.[Text133], 3)
    However, it is not accepting the Mid() into the CContentValue and says it is a data type mismatch?
    Your count could be off in some cases or the control may be null. Regardless, the message means the data involved does not fit the type expected.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 2
    Last Post: 11-10-2017, 04:38 AM
  2. Replies: 2
    Last Post: 08-25-2017, 08:16 AM
  3. Replies: 6
    Last Post: 11-13-2014, 01:44 PM
  4. Replies: 4
    Last Post: 08-11-2014, 01:18 PM
  5. Employee time clock with barcode scanning
    By trevor40 in forum Programming
    Replies: 2
    Last Post: 03-26-2014, 10:54 PM

Tags for this Thread

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