Results 1 to 9 of 9
  1. #1
    harhar0506 is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2017
    Posts
    11

    Barcode Scan

    I've designed a form and place a text box called A for inputting data from barcode. I would like to search a specific record (including fields B, C and D) from A (here 'Input') (i.e. list them out). And then add a time stamp on D and hope that the cursor goes back to text box A.

    I have tried the following:



    Private Sub Input_AfterUpdate()


    If Nz(Me.Input, "") = "" Then
    Me.Input.SetFocus
    End If


    End Sub




    Private Sub Input_BeforeUpdate(Cancel As Integer)


    Me![Time_Get] = Now()


    End Sub


    Private Sub Input_Change()


    If Nz(Me.Input, "") = "" Then
    Me.Input.SetFocus
    End If


    End Sub


    Private Sub Input_GotFocus()


    If Nz(Me.Input, "") = "" Then
    Me.Input.SetFocus
    End If


    End Sub

    and write a macro using On Enter for A ([SID] Like [Forms]![Query_System_1]![Input]).

    However, when I run the program, and start scanning the barcode, nothing happens. I really got frustrated... Thanks for any great person's help.

    harhar0506

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    ok, i dont think you want any of this code. Instead, the form's focus should be on the barcode box (tabindex = 0) so it starts in the barcode box.
    scan barcode,
    then do the other boxes get info FROM the barcode box? or does a user enter data into them?
    either way, no event code is needed since the form doesnt know if the user finished entering data in all the boxes, so you need a FIND button to gather all the box info and then search.

    Code:
    sub btnFind_click()
        'the query is built depending on the various filters the user picks...
    If Not IsNull(cboState) Then sWhere = sWhere & " and [state]='" & cboState & "'"
    If Not IsNull(txtName) Then sWhere = sWhere & " and [Name]='" & txtName & "'"
    If Not IsNull(chkContact) Then sWhere = sWhere & " and [Contact]=" & chkContact.Value
    
    'or LIKE '*' & txtBox & '*'
    
        'remove 1st 'AND'
    sWhere = Mid(sWhere, 4)
    
    'then open the continuous form of all records using the filter:
    
    docmd.openForm "frmList",,,sWhere
    end sub

  3. #3
    harhar0506 is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2017
    Posts
    11
    ranman256, thanks first. I'll try tmr when I'm back to office. Actually, I just want the helper to scan the barcodes continuously without pressing any button (just like stocktaking). is it possible to do this without the button? and while scanning, I hope the record can be retrieved (filtered) and a time stamp is added simultaneously. How should these be done? Thanks !

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Will every that is scanned bar code be in the database?

    If the scanned bar code is not in the database, what should happen?

    In the attached dB, enter 5 numbers that are in the list displayed. After a couple of numbers, enter a number that is not in the list.
    Attached Files Attached Files

  5. #5
    harhar0506 is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2017
    Posts
    11
    Many thanks, ssanfu. You gave me a great solution to solve a large part of my problem. ^_^

  6. #6
    harhar0506 is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2017
    Posts
    11
    Quote Originally Posted by harhar0506 View Post
    Many thanks, ssanfu. You gave me a great solution to solve a large part of my problem. ^_^
    ssanfu, I've tried to modify your code:

    Code:
    Private Sub OrderBarCode_AfterUpdate()
    
    Dim r As dao.Recordset
    Dim OrderBarCode As Variant
    
    Set r = Me.RecordsetClone
    
    Me.OrderBarCode = Me.OrderBarCode
    Me.Time_KeyIn = Now()
    Me.Dirty = False
    
    r.Close
    Set r = Nothing
    
    Me.OrderBarCode = vbNullString
    Me.OrderBarCode.SetFocus
    
    End Sub

    But, I have the following problems:
    1. The cursor did not go back to the 'OrderBarCode' textbox.
    2. When I tried to scan one barcode, the record is there. However, when I tried to scan two or more barcodes, the last record is there.

    Please shed light on me.

    Many thanks!

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I wouldn't expect your code to work. You've cut out all of the searching.

    Code:
     1    Private Sub OrderBarCode_AfterUpdate()
    
     2    Dim r As dao.Recordset
     3    Dim OrderBarCode As Variant
    
     4    Set r = Me.RecordsetClone
    
     5    Me.OrderBarCode = Me.OrderBarCode
     6    Me.Time_KeyIn = Now()
     7    Me.Dirty = False
    
     8    r.Close
     9    Set r = Nothing
    
    10    Me.OrderBarCode = vbNullString
    11    Me.OrderBarCode.SetFocus
    
    12    End Sub
    I added line numbers so I could talk about each line.

    Line 3: why is the variable declared as a variant?
    So I am guessing now you have a variable named "OrderBarCode", a control on the form named "OrderBarCode" and a field named "OrderBarCode"???

    Line 5: why are you setting the control on the form equal to itself???

    Line 6: whatever the current record is in the form, you just changed the control "Time_KeyIn" to the current date/time.

    Line 8: you closed the recordset, but you never used/referenced the recordset r....


    You should read and understand what the RecordsetClone is and how to use it. You never moved off of the record that was selected when the form opened.




    Do you understand HOW the example dB works?

    How many characters is your bar code? 12?

  8. #8
    harhar0506 is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2017
    Posts
    11
    ssanfu, thanks for your illustration. I finally finish the code based on your examples. Thanks again. ヾ(@^▽^@)ノ

  9. #9
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Great!

    Ready to mark this solved??

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

Similar Threads

  1. Bar code scan
    By Magnus1982 in forum Forms
    Replies: 1
    Last Post: 05-05-2017, 02:39 AM
  2. Barcode Scanner Invalid Scan
    By nick243 in forum Access
    Replies: 2
    Last Post: 06-13-2016, 02:09 PM
  3. Is this barcode a working barcode?
    By panoss in forum Access
    Replies: 2
    Last Post: 11-06-2014, 10:10 AM
  4. Barcode Scan input
    By Nem3s1S in forum Database Design
    Replies: 4
    Last Post: 09-26-2009, 09:43 AM
  5. Replies: 1
    Last Post: 12-30-2008, 08:58 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