Go to next field (enter) when using barcode scanner (1 Viewer)

bruceblack

Registered User.
Local time
Today, 08:46
Joined
Jun 30, 2017
Messages
119
Hi folks! This is kind of an odd one that doesnt make much sense to me.
Please help!

So i have a form with some fields.
I'm using a barcode scanner to put in the values from the barcodes.
This WORKS for all my fields except for 1 which has code on after update event.
But i can't seem to figure out how to fix it. SetFocus wont work either.
Also the enter key behaviour is set to default.

CODE:

Sub article_afterupdate()
vVal = DLookup("[location]", "import_cyclecountTXT", "[location]='" & article & "'") 'lookup item
If IsNull(vVal) Then
'do nothing

Else
location.Value = article
Me.article = Null
Me.partij.SetFocus
Me.article.SetFocus
End If
End Sub


I just want it to go to the next field after entering normal data with the scanner. But instead, it enters the data, highlights it, and stays on the same control.

What is going on here?
 

Gasman

Enthusiastic Amateur
Local time
Today, 08:46
Joined
Sep 21, 2011
Messages
14,267
Code:
Sub article_afterupdate()
vVal = DLookup("[location]", "import_cyclecountTXT", "[location]='" & article & "'") 'lookup item
If IsNull(vVal) Then
'do nothing

Else
location.Value = article
Me.article = Null
Me.partij.SetFocus
[COLOR="Red"]Me.article.SetFocus[/COLOR]
End If
End Sub
 

bruceblack

Registered User.
Local time
Today, 08:46
Joined
Jun 30, 2017
Messages
119
Thanks Gasman, i see what youre trying to say.
Though, this is not the problem.

That codes says, if i put in a value that is a location, copy it to the location field and go back to the article field. Which is correct.

When the value returns 0, its supposed to go the partij field.
But it doesnt work.

Sub article_afterupdate()
vVal = DLookup("[location]", "import_cyclecountTXT", "[location]='" & article & "'") 'lookup item
If IsNull(vVal) Then
'do nothing

Me.partij.SetFocus
<<<<<<<< when i try this, it doesnt work either

Else
location.Value = article
Me.article = Null
Me.partij.SetFocus
Me.article.SetFocus
End If
End Sub




When i press enter, it does work. I just doesnt work with my barcode scanner for that particular field. Maybe i can press ENTER with vba????
Another thing, if i setfocus to another field it does work! It just doesnt want to go to partij field....
 
Last edited:

Gasman

Enthusiastic Amateur
Local time
Today, 08:46
Joined
Sep 21, 2011
Messages
14,267
Not sure what you are trying to do.?
To me it makes no sense to overwrite the first article entered with any subsequent article.?

Walk through the code with the debugger.
Everything you are saying points to the fact that vVal is not NULL ?
You have to ensure the code logic actually happens. You first code did not have that setfocus command. the fact that you have now added it and it does not do anything would lead me to believe it is never executed?

You now say 'When the value returns 0, its supposed to go the partij field.', so why are you checking for NULL?
 

bruceblack

Registered User.
Local time
Today, 08:46
Joined
Jun 30, 2017
Messages
119
This is a cycle count program. So the end user should not be bothered by the fact there is a difference between a location, item, or partij (serial number).
Thats why i have code that recognize if the entered value is a location or not.

In case its not, it should do nothing in particular.
Just enter the value and skip to the other field.
But SetFocus doesnt seem to work with my barcode scanner.
The enter key does.
 

Gasman

Enthusiastic Amateur
Local time
Today, 08:46
Joined
Sep 21, 2011
Messages
14,267
OK, never having worked with a barcode scanner, there might be another step you might need to do?, however I would check to see if it works when the location is found?
You would need to comment out the article setfocus command to test.

You can use Sendkeys to get past your problem if there is not another way. That will emulate what you are doing now. Never had to use it myself yet.

http://www.contextures.com/excelvbasendkeys.html
 

bruceblack

Registered User.
Local time
Today, 08:46
Joined
Jun 30, 2017
Messages
119
Thanks Gasman, SOLVED it. By using a keysend in the VBA.

SendKeys "{ENTER}"

Now it works. Something to do with the scanner not sending an enter.
You can program them for these things, but couldnt find the right code.

Anyways, it works. The Dlookup was working fine. No need to edit it.

Thanks!
 

Users who are viewing this thread

Top Bottom