Solved

VB Onchange or GotFocus

Posted on 2010-08-25
5
557 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
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:deepusreedhar
deepusreedhar 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB6 Compile Compatibility Issue 4 102
How can I sort the data shown in Sheet 1 and copy it to Sheet 2? 8 51
Export Data to Different .csv Files 26 103
VBSScript Error IP Array 6 21
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

815 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now