Solved

VB Onchange or GotFocus

Posted on 2010-08-25
5
563 Views
Last Modified: 2013-12-26
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
Comment
Question by:CRS6205
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 3

Accepted Solution

by:
omnimaven earned 125 total points
ID: 33526552
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
 
LVL 4

Assisted Solution

by:avarmaavarma
avarmaavarma earned 125 total points
ID: 33526630
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
 
LVL 3

Assisted Solution

by:Deepu Sreedhar
Deepu Sreedhar earned 125 total points
ID: 33529625
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
 
LVL 14

Assisted Solution

by:Brook Braswell
Brook Braswell earned 125 total points
ID: 33530526
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
 

Author Closing Comment

by:CRS6205
ID: 33562975
They did answer my question to a point then brought up a new way on how it should be done without further explanation.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question