Barcode scanning Example (1 Viewer)

pekajo

Registered User.
Local time
Today, 15:39
Joined
Jul 25, 2011
Messages
133
Hi,

I maybe pushing my luck but does someone have a simple example MS Access database that reads a barcode reader and loads the barcode into a table.

Hoping you can help
Regards
peter
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 22:39
Joined
Aug 30, 2003
Messages
36,133
Don't have a sample, but basically a barcode reader provides keyboard input. You can simply have a textbox to accept the barcode input and use the update events to handle the input. You can test without a reader simply by typing "123" into a textbox and hitting enter. That's basically what the reader will do.
 

pekajo

Registered User.
Local time
Today, 15:39
Joined
Jul 25, 2011
Messages
133
Hi,

Thanks pbaldy, could I push my luck a little and ask how I would code below
Scan barcode
Add new record to a table
empty field
Scan next bar code
...
...
Then I would press enter to finish


Thanks
Peter
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 22:39
Joined
Aug 30, 2003
Messages
36,133
I would open a recordset on the table and use the AddNew method of it in the after update event of the textbox.
 

tt1611

Registered User.
Local time
Today, 01:39
Joined
Jul 17, 2009
Messages
132
Here some code you can put behind a textbox as pbaldy said. This code went into action ont he after update event
Code:
Private Sub txtscan_AfterUpdate()
If Me.txtscan = "" Or IsNull(Me.txtscan) = True Then
MsgBox "No barcode/serial detected", vbOKOnly + vbExclamation, "Error"
Else
Dim rst As DAO.Recordset
Dim rst1 As DAO.Recordset
Dim strSQL As String
Dim strSQL1 As String
strSQL = "SELECT NetDevice_HR_Type FROM networkdevices WHERE netdevice_serial = '" & Me.txtscan & "'"
strSQL1 = "SELECT Device_HR_Type FROM devices WHERE device_serial = '" & Me.txtscan & "'"
Set rst = CurrentDb.OpenRecordset(strSQL)
Set rst1 = CurrentDb.OpenRecordset(strSQL1)
If rst.RecordCount <> 0 Then
If rst!NetDevice_HR_Type = "NAF" Or IsNull(NetDevice_HR_Type) = True Then
MsgBox "NAF/Non Assigned devices cannot be processed", vbOKOnly + vbExclamation, "Error"
Me.txtscan = ""
Me.cmdclose.SetFocus
Me.txtscan.SetFocus
Else
'Insert code here
End If
Else
If rst1.RecordCount <> 0 Then
If rst1!Device_HR_Type = "NAF" Or IsNull(rst1!Device_HR_Type) = True Then
MsgBox "NAF/Non Assigned devices cannot be processed", vbOKOnly + vbExclamation, "Error"
Me.txtscan = ""
Me.cmdclose.SetFocus
Me.txtscan.SetFocus
Else
'Insert code here
End If
Else
MsgBox "Device not found", vbOKOnly + vbExclamation, "Error"
Me.txtscan = ""
Me.cmdclose.SetFocus
Me.txtscan.SetFocus
End If
End If
End If
End Sub
 

Alvinwhit

Registered User.
Local time
Today, 00:39
Joined
Sep 17, 2012
Messages
13
Hello, I would like to know if this could work for scanning credit cards, if so what changes (if any) would I have to make?
 

tt1611

Registered User.
Local time
Today, 01:39
Joined
Jul 17, 2009
Messages
132
scanning credit cards?? - are you trying to write for scan or swipe.
Had to check my card for a sec and nope...no barcode on the visa
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 22:39
Joined
Aug 30, 2003
Messages
36,133
My credit card has a weird barcode on it...wait, no, that's my face. :p

My response for a swiper would be the same as post 2 for a barcode scanner. The swiper provides keyboard input. Attach one, put focus in Notepad and swipe your credit card. You'll see what it returns and can then figure out how to handle it.
 

rickober

Registered User.
Local time
Today, 01:39
Joined
Dec 12, 2012
Messages
10
I have a related issue: I have a form that collects credit card info from a swiper. THere is an unbound text box that will collect the data which will then be parsed and sent to the credit card processor directly from the form (This is VERY elegant so if anybody needs to know how to do this, contact me roberle AT geoinsights.biz).

The issue is how does one identify where the data is coming from? THere are a lot of fields besides the credit card box and I want to allow a user to enter information there via the keyboard or by selecting a combo box. But if s/he swipes a card, the form needs to detect that the data is coming from the HID (the swiper), set the focus to the txtbox, the data then goes into the txtbox, and then the code continues on from there. The trouble is that the data from the swiper goes into whatever field has the focus and I would like eliminate the need for the user to click into the credit card field.
Any ideas??
Thanks,
Rick
 

spikepl

Eledittingent Beliped
Local time
Today, 07:39
Joined
Nov 3, 2010
Messages
6,142
This is how I would try to make it do what you want.

Most scanneres can be programmed. If your credit card thing can be programmed, you could make it send some special character at the beginning of the string which would cause the form to set focus to the appropriate control. You'd have to look at the Form's Key Down event to intercept that character (or combination of characters) and you'd need to set the Key Preview property , at the bottom of Event tab, to Yes.
 

rickober

Registered User.
Local time
Today, 01:39
Joined
Dec 12, 2012
Messages
10
Good idea! This is the type of data (an actual credit card scan-modified) that comes from a credit card reader: %B5466474000831111^xxxxx/xxxxx ^13011012000000955000000?;5466474000831111=130110120000955?

so the "%" character would be the trigger. The Key Down event, however, looks at all the characters, not just the first. Here is the code that doesn't work:
If KeyCode = Chr(37) Then
Exit Sub
Me.CCSCAN.SetFocus
End If

Any suggestions?? Most grateful for anything.
 

candy357

New member
Local time
Yesterday, 22:39
Joined
Jul 11, 2013
Messages
1
Here is a detailed barcode scanning guide with C# and VB sample codes in .NET projects. You can refer to it.
 

Users who are viewing this thread

Top Bottom