Bar Code Search Field Help Please

N

Nigel Bate

Hi everyone. I have a tapes database to record the companies master tapes. I
have a field in which to add a bar code using a barcode scanner.
I have made an unbound box(txtFind) that I want to use as a record search
box for the user, i.e. to input the barcode via the scanner into this
unbound field and i need it to automatically find the record corresponding
to the code in the Bar Code field.
I have managed in the txtFind fields 'On Change' property to enter the
barcode via a scanner, and bring up the MS Find dialog, but it misses out
the first number. I then need to have it find the record the close the MS
Find dialog.
Is this possible, or is there code that I could use that would emulate this
action.
Please help
Nigel Bate
 
G

Guest

The OnChange event will fire after each character is entered. When you read a
barcode, it enters characters the way you type them: one character at a time.
This means that the OnChange event fires after the first character is read
and the remaining characters are being out into the Find dialog.
What I think you want is to use the AfterUpdate event to open the find
dialog. This assumes that your barcode reader appends a Tab or Carriage
Return character to fire the event.

HTH,
Barry
 
M

msnews.microsoft.com

Baryy,
Thank you for your quick responce. Yes I can use the AfterUpdate event to
bring up the Find dialog, but I am after is it all to happen automattically,
so all the user has to do is click on the txtFind field and enter the
BarCode useing the scanner, and having the record found for them without
having to touch any other controls. i.e. The user scans in the barcode, then
automatically the following happens in the background; openning of the Find
dialog, seing the scaned barcode number, finding the record and closing the
Find dialog.
Can this happen, or is VB code on the field the best way - in which case is
there a sample I could use.
Thank you for any help !
Regards
Nigel
 
G

Guest

I think you should do this without the Find dialog. In the textbox's
AfterUpdate, do something like this...

Private Sub txtFind_AfterUpdate()
Dim rsClone As DAO.Recordset
Set rsClone = Me.Recordsetclone
rsClone.FindFirst "[MyFieldName] = '" & Me.txtFind & "'"
If Not rsclone.NoMatch Then
Me.Bookmark = rsClone.Bookmark
End if
rsClone.Close
End Sub

This requires that you have a reference to the Microsoft DAO Object Library
(In VBE, Tools, References).

HTH,
Barry
 
M

msnews.microsoft.com

Barry, many many thanks, I will try this when I get back to the office on
Monday. What version of DAO for an Access 2000 DB running with Access 2003
Runtime(on users PCs) do I nead, I know there are a few i.e. 3.0, 3.5, 3.51,
3.6. Also I take it that MyFieldName respondes to txtFind.
Again many thanks for your swift help an example.
Nigel Bate
Barry Gilbert said:
I think you should do this without the Find dialog. In the textbox's
AfterUpdate, do something like this...

Private Sub txtFind_AfterUpdate()
Dim rsClone As DAO.Recordset
Set rsClone = Me.Recordsetclone
rsClone.FindFirst "[MyFieldName] = '" & Me.txtFind & "'"
If Not rsclone.NoMatch Then
Me.Bookmark = rsClone.Bookmark
End if
rsClone.Close
End Sub

This requires that you have a reference to the Microsoft DAO Object
Library
(In VBE, Tools, References).

HTH,
Barry

msnews.microsoft.com said:
Baryy,
Thank you for your quick responce. Yes I can use the AfterUpdate event to
bring up the Find dialog, but I am after is it all to happen
automattically,
so all the user has to do is click on the txtFind field and enter the
BarCode useing the scanner, and having the record found for them without
having to touch any other controls. i.e. The user scans in the barcode,
then
automatically the following happens in the background; openning of the
Find
dialog, seing the scaned barcode number, finding the record and closing
the
Find dialog.
Can this happen, or is VB code on the field the best way - in which case
is
there a sample I could use.
Thank you for any help !
Regards
Nigel
 
G

Guest

It doesn't matter too much which DAO version you use, but I would suggest 3.6.

MyFieldName refers to the field name in your underlying recordset; the field
in your table or query, not the form control.

Barry
 
N

nigel Bate

Barry, Again many thanks for all of help. Final thing, as I'm not much of a
programer, do I need to make any declarations or does the code run by
itself.
Nigel
 
G

Guest

The code should run as is, but, as I mentioned, you'll need to reference the
DAO library.

Barry
 
N

Nigel Bate

Barry,
I have try'd the code you sujested by I get a "Runtime error 3464" Data
type mismatch in criteria expression. The code window highlights the line;
rsClone.FindFirst "[BarCode] = '" & Me.txtFind & "'"
I have added DAO 3.6, the table field BarCode is number (long integer) and
the unbound txtFind field is set to Standard number format.
I have obviousely forgotten something but cannot see what.
Can you easily see the problem ?

Regards
Nigel
 
N

Nigel Bate

Barry, sorry - found the answer on MSoft site. numbers do not need '
delimiters.
Thank you for all your help
Regards
Nigel
 
G

Guest

Nigel,

Sorry. I incorrectly assumed the table field was text. Change the statement
to:
rsClone.FindFirst "[BarCode] = " & Me.txtFind
You need to take out the two single quotes for a numeric field.

Barry

Nigel Bate said:
Barry,
I have try'd the code you sujested by I get a "Runtime error 3464" Data
type mismatch in criteria expression. The code window highlights the line;
rsClone.FindFirst "[BarCode] = '" & Me.txtFind & "'"
I have added DAO 3.6, the table field BarCode is number (long integer) and
the unbound txtFind field is set to Standard number format.
I have obviousely forgotten something but cannot see what.
Can you easily see the problem ?

Regards
Nigel
Barry Gilbert said:
The code should run as is, but, as I mentioned, you'll need to reference
the
DAO library.

Barry
 
G

Guest

MS Access 2003 / Windows XP Pro / wedge scanner

I have just started implementing barcodes and while I was trying to find a
method of automatically pulling up one record after another by just scanning
bar codes. I found this post which was extremely helpful.

I have one problem that I was hoping to get assistance with however. I have
a form with an OnOpen event to automatically set focus to the BARCODEINPUT
field which is an unbound control. Then I used your code to find records by
barcode...

Private Sub BARCODEINPUT_AfterUpdate()
Dim rsClone As DAO.Recordset
Set rsClone = Me.RecordsetClone
rsClone.FindFirst "[ID] = " & Me.BARCODEINPUT
If Not rsClone.NoMatch Then
Me.Bookmark = rsClone.Bookmark
End If
rsClone.CLOSE
End Sub

This works wonderfully when scanning in different barcodes each time. The
problem comes in when the same barcode as the current record is scanned.
When this happens, the form moves from the correct record to the next record
and sets the focus to the next field, I assume because the scanner has an
automatic carriage return. All subsequent scans just change data, of course.
I would like for it to display the same record when the same code is scanned
repeatedly with the focus remaining in the BARCODEINPUT field. Granted,
there is no purpose for scanning the same barcode repeatedly; however, I try
to forsee possible User errors.
 
G

Guest

I'm not really sure why it would move to the next record. However, I think
both of your problems might be solved by moving the code to the BeforeUpdate
event and adding Cancel=True to the end of the routine. This would probably
eliminate the effect of the built-in carriage return.

HTH,
Barry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top