Solved

VB Onchange or GotFocus

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 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

10 Experts available now in Live!

Get 1:1 Help Now