Database with barcode scanner (1 Viewer)

Emma35

Registered User.
Local time
Today, 11:41
Joined
Sep 18, 2012
Messages
467
Hi Guys,
I've been asked to create a database which allows Users to scan barcodes on various raw materials being used on site here. I'm not sure if it's a problem but each item has two barcodes which i would like to be able to scan as one record. I was thinking maybe have two fields on a main form to display the barcodes when scanned and then the relevant information be displayed in fields on a subform (Batch No, BBE Date, Product Name etc).
I would then need to be able to save the info on the subform to a table for traceability. Is this something that's relatively easy to accomplish ?

This is just an initial enquiry before i get started....i can provide details of the type of barcodes and scanner when i find out more.

Thanks a lot,
Em
 

adhoustonj

Member
Local time
Today, 14:41
Joined
Sep 23, 2022
Messages
150
I use a scanner in a few of my databases with the InputBox function.

Code:
Private Sub emp_Click()
Dim inbox As String
Dim trainee As LongPtr

Set db = CurrentDb()

inbox = InputBox("Trainee please scan your badge")
If inbox = "" Then
    DoCmd.Close
    Exit Sub
End If
trainee = CLngPtr(inbox)

strSQL = "SELECT tblEmployees.emp_id, tblEmployees.user " _
& "FROM tblEmployees " _
& "WHERE (((tblEmployees.badge)=" & trainee & "))"
Set rs = db.OpenRecordset(strSQL)
If rs.RecordCount > 0 Then
    trainee = rs.Fields("emp_id")
    Me.txt_trainee = trainee
    Me.emp = rs.Fields("user")
Else
    MsgBox ("Your badge is not currently in the system")
    DoCmd.Close
End If

'rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
 

GPGeorge

Grover Park George
Local time
Today, 11:41
Joined
Nov 25, 2004
Messages
1,873
First, you should design this as a parent table for raw materials, and a child table that has the bar codes for each raw material, in a one-to-many relationship. The reason for that is you don't want to get trapped in a design that only permits two bar codes for a raw material. Right now, that's the case; there is no guarantee it will remain that way.

Bar code input is just a string of digits, so no matter what type of barcode and scanner you use, the task is just getting the scanned value from the barcode scanner into the control on the form which is bound to the barcode field in the barcode table.
 

MsAccessNL

Member
Local time
Today, 20:41
Joined
Aug 27, 2022
Messages
184
I think that you have to scan 2 times to get both the barcodes. Most scanner can be set with a automated "Enter" after the scan this trigger Access to go to the next field/control. So two barcode fields makes the most sense to me. The question is, which data are you going to link to which of the two barcodes, or in other words do both barcodes get the same primary key?
 

Emma35

Registered User.
Local time
Today, 11:41
Joined
Sep 18, 2012
Messages
467
First, you should design this as a parent table for raw materials, and a child table that has the bar codes for each raw material, in a one-to-many relationship. The reason for that is you don't want to get trapped in a design that only permits two bar codes for a raw material. Right now, that's the case; there is no guarantee it will remain that way.

Bar code input is just a string of digits, so no matter what type of barcode and scanner you use, the task is just getting the scanned value from the barcode scanner into the control on the form which is bound to the barcode field in the barcode table.
Thanks for the suggestion George. I'm not sure a table like that would work in this instance as the barcodes would be different each time even for the same raw material. Batch numbers would change with each delivery, which would be reflected in the barcode.
 

Emma35

Registered User.
Local time
Today, 11:41
Joined
Sep 18, 2012
Messages
467
I think that you have to scan 2 times to get both the barcodes. Most scanner can be set with a automated "Enter" after the scan this trigger Access to go to the next field/control. So two barcode fields makes the most sense to me. The question is, which data are you going to link to which of the two barcodes, or in other words do both barcodes get the same primary key?
How to you get the scanned barcode to separate into the relevant controls on the form ?
 

GPGeorge

Grover Park George
Local time
Today, 11:41
Joined
Nov 25, 2004
Messages
1,873
Thanks for the suggestion George. I'm not sure a table like that would work in this instance as the barcodes would be different each time even for the same raw material. Batch numbers would change with each delivery, which would be reflected in the barcode.
That's not really pertinent to the point.

This is a one-to-many relationship between raw material batches and barcodes. One batch of raw materials has two or more barcodes. The fact that each batch of raw materials has barcodes pertinent only to that batch does not change this relationship. At this point, there are two barcodes per batch. It is tempting, as it always is, to conclude that this situation will persist indefinitely. It's likely. Unfortunately, it's not guaranteed. There may come a time when you need a third, or even a fourth, bar code per batch. Wise design indicates we plan for the future.

Here, the problem presents as having to "point" the barcodes at one of two controls on a form. That is ALSO resolved by having a subform with a single barcode control into which the barcodes are entered and saved.

I think going down the path of trying to directing data entry to different controls on the fly, or parsing scanned bar codes into two segments for the different fields, and so on is a bigger problem than simply following the general pattern of good relational design in both the table and interface.

Of course, that's advice one can freely accept or reject. It's offered as an alternative to consider.
 

Emma35

Registered User.
Local time
Today, 11:41
Joined
Sep 18, 2012
Messages
467
That's not really pertinent to the point.

This is a one-to-many relationship between raw material batches and barcodes. One batch of raw materials has two or more barcodes. The fact that each batch of raw materials has barcodes pertinent only to that batch does not change this relationship. At this point, there are two barcodes per batch. It is tempting, as it always is, to conclude that this situation will persist indefinitely. It's likely. Unfortunately, it's not guaranteed. There may come a time when you need a third, or even a fourth, bar code per batch. Wise design indicates we plan for the future.

Here, the problem presents as having to "point" the barcodes at one of two controls on a form. That is ALSO resolved by having a subform with a single barcode control into which the barcodes are entered and saved.

I think going down the path of trying to directing data entry to different controls on the fly, or parsing scanned bar codes into two segments for the different fields, and so on is a bigger problem than simply following the general pattern of good relational design in both the table and interface.

Of course, that's advice one can freely accept or reject. It's offered as an alternative to consider.
Ok so how do i set up what you're suggesting ?. I'm told there will never be more than two barcodes....and if there is in the future, i won't be there to worry about it !. Are you saying that scanning the barcode and then having the relevant pieces of information from that code separate into the various controls on my form is not possible ?

Thanks
 

GPGeorge

Grover Park George
Local time
Today, 11:41
Joined
Nov 25, 2004
Messages
1,873
Ok so how do i set up what you're suggesting ?. I'm told there will never be more than two barcodes....and if there is in the future, i won't be there to worry about it !. Are you saying that scanning the barcode and then having the relevant pieces of information from that code separate into the various controls on my form is not possible ?

Thanks
Not really. Almost anything is possible. Some things are harder to do, some easier. Some things make sense, some don't.

Let's start by reviewing the facts. Maybe you already explained this, but I'm not sure I read it.

What are the two barcodes? What do they represent? Why do you record them?
 

Emma35

Registered User.
Local time
Today, 11:41
Joined
Sep 18, 2012
Messages
467
Not really. Almost anything is possible. Some things are harder to do, some easier. Some things make sense, some don't.

Let's start by reviewing the facts. Maybe you already explained this, but I'm not sure I read it.

What are the two barcodes? What do they represent? Why do you record them?
Ok well the first barcode contains the following
Product Name
Product ID
Batch Number

The second barcode contains
Product Weight
Pallet ID

Don't ask me why there needs to be two barcodes but i'm stuck with it unfortunately

Thanks again for your help
 

GPGeorge

Grover Park George
Local time
Today, 11:41
Joined
Nov 25, 2004
Messages
1,873
Ok well the first barcode contains the following
Product Name
Product ID
Batch Number

The second barcode contains
Product Weight
Pallet ID

Don't ask me why there needs to be two barcodes but i'm stuck with it unfortunately

Thanks again for your help
Thanks. My guess would be that there are too many bits of information to include them all in a single bar code, or that they are created at different times for different purposes. The first identifies the product coming of the production line; the second identifies the specifics for an individual pallet. That makes sense to me. It also suggests that there is potential for additional bar coding in the future should the organization decide to add a different type of information to each pallet, such as the customer for whom it is intended. See why I am allergic to putting repeating fields in tables? They make future extensibility much harder.

So, I would create, as previously suggested, a table for scanned bar codes and I would NOT try to input them through a single input field. They are two things, and they need to be handled as such.

The Barcode scan table would need a Primary Key, a Foreign Key to the Raw Material Table, a BarcodeType field, and a ScannedBarCode field. I see the two current BarcodeTypes as "ProductionCode" and "PackagingCode", or similar names that reflect the two different purposes.

The way I would do this would be to create a main form/sub form for data entry. The sub form can be relatively small as it needs only two field and two records.

The main form is bound to the raw materials table. The sub form is bound to the barcode table. The Link Master Fields/Link Child Fields property is set to the Primary Key and Foreign Key pair that related raw materials to bar codes.

Users put focus on the subform control and select the BarcodeType from a dropdown. Then they put focus on the barcode field for that record and scan the appropriate barcode. Then they put focus on the dropdown and select the other BarcodeType. Focus goes to the barcode field for that record and the other barcode is scanned. You can automate some of this so that focus automatically moves from control to control.

The alternative, in which both barcodes are scanned into a single text control on a form, requires some interesting logic. First, you have to validate the entry. It has to contain two and only two barcodes. There has to be one barcode of each type, Production and Packaging. They have to be in the proper sequence, although you could probably add a logic step to inspect the raw input and decide which of the two parts is the Production code by comparing it to a pattern.

You'd probably need to add a step in there to have the user insert a separator after the first and before the second scanned barcode to make splitting them easier. That might be automated, but I can't think of a simple way to do that off the top of my head. Maybe just a command button to click after the first scan, and a second command button to start the parsing and validation step in the VBA.

Once the input is split and validated, your code would then insert the appropriate scanned code into the appropriate fields in the table.

Yes, doable, but it falls under what I call the "Code Wad" approach to designing Access.

It's like this. A lot of things can be done pretty directly using standard table design and interface design, with enough code to smooth the operation.

Or, a lot of code, wads and wads of it, can be written to manipulate and manage data .

The latter sometimes can't be avoided, when tasks are truly complex. But being lazy means I'd much rather use the "out of the box" tools and methods and avoid writing a wad of new code.
 

Emma35

Registered User.
Local time
Today, 11:41
Joined
Sep 18, 2012
Messages
467
Thanks again for your time George. Just to clear something up i'm not trying to scan two barcodes into one field. I was going to create two text boxes on the form (one for each barcode). I have a bit more information now......i'm told there has only been two barcodes for the last 30 yrs and this will not change.
So when i scan a barcode into Notepad it comes out like this 1524011410612768240DA110587
This barcode prints on the pallet sticker as follows (15) 240114 (10) 612768 (240) DA110587

The info is 240114 (BB Date) 612768 (Batch No) and DA110587 (Product ID)

Are the numbers in brackets some kind of separator ?
Could i put some VBA in the OnChange event of the txt boxes to parse the various bits of info into the relevant fields on the form ?
What do you think ?
 

MsAccessNL

Member
Local time
Today, 20:41
Joined
Aug 27, 2022
Messages
184
If the barcode and the batch numbers always have the same length, then you can use the Mid() function like mid("1524011410612768240DA110587",3,6) wil give 240114.
 
Last edited:

MsAccessNL

Member
Local time
Today, 20:41
Joined
Aug 27, 2022
Messages
184
Converting the string 240114 to an actual Date (isoDate or local dateformat) is an interesting question ?
 

Minty

AWF VIP
Local time
Today, 19:41
Joined
Jul 26, 2013
Messages
10,371
I think that (best before) date is simply YYMMDD ?
 

Emma35

Registered User.
Local time
Today, 11:41
Joined
Sep 18, 2012
Messages
467
Yes the BB Date is 14/01/2024. That's just the format it's in on the barcode. The batch numbers and even the Product ID numbers will not always be the same length.
 

GaP42

Active member
Local time
Tomorrow, 04:41
Joined
Apr 27, 2020
Messages
338
What are the leading 2 digits (15 in the sample)? Is there a checksum for the barcode?
Sorry - you indicated you do not know in post #12. You need some technical information from the barcode provider / reader - it should be of a defined format, and it may be useful.
 

Emma35

Registered User.
Local time
Today, 11:41
Joined
Sep 18, 2012
Messages
467
What are the leading 2 digits (15 in the sample)? Is there a checksum for the barcode?
Sorry - you indicated you do not know in post #12. You need some technical information from the barcode provider / reader - it should be of a defined format, and it may be useful.
I'm actually not really sure. I've got somebody looking into it for me. The scanners in use are pretty old and nobody knows much about them
 

Emma35

Registered User.
Local time
Today, 11:41
Joined
Sep 18, 2012
Messages
467
Some more info on the scanner. It's a Zebra LI3678 and i managed to get some tech help regarding adding a Tab event after a barcode has been scanned. That's working now, so now i have to work out how to get the information within the barcode into the correct field controls
 

MarkK

bit cruncher
Local time
Today, 11:41
Joined
Mar 17, 2004
Messages
8,181
Hey all,
I wrote a library database a while back that contains a class that raises a BarcodeScan event. The Zebra CCoreScanner software exposes an API you can reference in Access, so this library references that API, and basically does all the legwork, but the upshot is that you no longer need to point the keyboard focus to a Textbox control or InputBox to handle your scan. Instead, you can handle the BarcodeScan event in your code, and just read the barcode internally, and decide what to do with the result without any concern about what user interface element is going to handle the result.

First, you unzip and set a reference to the attached database, MyScanner.accdb. Then, at it's simplest, you write code like this on a form...
Code:
Private WithEvents scan_ As MyScanner.cMyScanner

Private Sub Form_Open(Cancel As Integer)
    Set scan_ = MyScanner.New_Scanner
    scan_.OpenScanner
End Sub

Private Sub scan__BarcodeScan(ScanText As String)
    MsgBox ScanText
End Sub

MyScanner.cMyScanner is a PublicNotCreatable class in MyScanner.accdb. To get an instance of the class, call the MyScanner.New_Scanner method, and assign that result to a WithEvents variable in your code. Then call the OpenScanner method, and your scanner should beep. Then, if you scan something, you can handle that scan without respect to your user interface.

Cheers,
 

Attachments

  • MyScanner.zip
    39 KB · Views: 161

Users who are viewing this thread

Top Bottom