• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 578
  • Last Modified:

VB Onchange or GotFocus

I have been asked to create a application. VB is the only way I know how to get this running while using access. Any way I have a textbox - Text1, when a person scans in a SKU number I would like it to search a database and find that SKU number then increment another field by 1.

 I guess my question is that would it be better to use onChange with SELECT command or GotFocus? And how do I incorporate the SELECT command.

 I do not want the person to have to click on anything. Just automatically increment on each scanned sku number.
0
CRS6205
Asked:
CRS6205
4 Solutions
 
omnimavenCommented:
You don't want to use the GotFocus event since you want that textbox to have focus and keep focus at all times. I would use the OnChange event. If you aren't worried about someone trying to hack your program, you can use SQL like:

"SELECT <columns list> from <table name> where SKU = '" & txtbox.Text & "'"

If you are worried about hackers, then you want to use a stored procedure.
0
 
avarmaavarmaCommented:
Using the OnChange will only help if the user actually 'leaves' the textbox - i.e. if the textbox loses focus
It will only fire if your textbox loses focus or you hit enter. The other problem with the onChange is that it fires every single time the textbox changes - so if your SKU is 'ABC', it will fire 3 times.

It really sounds like you want to use the 'Leave' event of the Textbox. This fires only when the text entry is completed and the focus is lost from this field.

Are you building a webapp or a Desktop app?

Thanks
0
 
Deepu SreedharBI Software EngineerCommented:
Hi,
    Are you using a scanner for scanning in the code? In that case the scanner puts a return character at the end. So you can check the key press event for KeyAscii=13 and do the rest in there.
0
 
Brook BraswellApplication Development ManagerCommented:
Since you may or may not have focus on the text box when you start....
1.  Set Focus on load of the form.

Do you have other controls on your form ?
If you do NOT then
2.  Set Focus to the Text Box on key press event of the form...

As Deepusreedhar said, Use the Trap for the Enter Key (ascii 13 )...

When would you like to change color of your text box and what would be the purpose of changing the back color ?  You can set the color at several points.
1.  When you are receiving data from your text box.
2.  When your text box has focus.
3.  When the enter key has been pressed - run your query ( as a hard code SQL or a stored procedure )
4.  When your SQL has successfully found a good code.

then you can decide - Increment your counter for each scan?  or increment for each GOOD scan?  

0
 
CRS6205Author Commented:
They did answer my question to a point then brought up a new way on how it should be done without further explanation.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now