Solved

VB Onchange or GotFocus

Posted on 2010-08-25
5
555 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

932 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

15 Experts available now in Live!

Get 1:1 Help Now