visual basic express 2008 textbox coding - beginner!

I am learning VB exp 2008 with a book in my hand......
I would like to use a textbox in a panel to input 4 numeric characters, then pass that data to an opening string for an ADONet connection to an access database in order to select a particular record

I thought to use the textbox TextChanged event to count 4 character entry then create the request without having to click a "go" button. (I'm not interested at the moment on the error checking for numerics).

I open the database connection in the form load event using the following:

m_cnADONetConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\visual_basic_tests\test1.mdb"

 but thought to submit the 4 digit numeric ID from the TextChanged event after 4 characters are entered (and checked!) like this: (the numbers are held in an integer variable intIDNumber and the database field to be searched is ID_Number)

m_daDataAdapter = New OleDb.OleDbDataAdapter("Select * From TestTable where ID_Number = intIDNumber", m_cnADONetConnection)
        m_cbCommandBuilder = New OleDb.OleDbCommandBuilder(m_daDataAdapter)

I am not sure how to write the TextChanged code to loop until 4 characters are entered then
select the record, close the panel and display the result in textboxes in another panel.

I got this far then realised I hadn't a clue what to do next!

Private Sub txtGetData1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtGetData1.TextChanged
        strResult = txtGetData1.Text
        intIDNumber = CInt(strResult)
        intCount = intCount + 1
        If intCount = 4 Then
        End If
      End Sub

intCount is declared in the class declarations at the top of the form

In another test i have successfully populated the m_dataAdapter with all the records and can  display and move through the records and change and save, so the connection works (using the select * without the where) but I need to select a single record for global use over several forms.

Hope its clear!

There will be more....


Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
Welcome to the wonderful world of .NET development!!

Here are some thoughts to help you along:

1) I assume that 'intCount' is a module-level variable to count the characters entered.  If you don't reset this value, it will just continue to increase, and will only equal 4 one time.

2) Another approach is to check the text length.

3) I am not quite sure that I understand what "select the record" means...  Are you saying that you want to use the entered value, and call the Fill method to get the data into the DataTable?

4) Where is the " m_daDataAdapter.Fill(m_dtTest1) line defined?

5) Do you want to use a data-binding technique to bind the TextBox controls to the DataTable?
chrisatworkAuthor Commented:
Thanks for the welcome! (it's a far cry from Basic in the early '80's).

Ok, using the book, I can now connect to my access database and retrieve the complete set of records into a data table.  I can then display  each complete record in a panel containing text boxes for individual fields. Additional buttons in the panel give me first, last, forward 1 and back 1 options to move around the records, together with a save button.  This is a fairly standard arrangement for which I have copied  code from the web as well as reading the book.

So I can modify individual records within the set.  I know how to save the modifications back to the database and (in theory, not yet done) add and delete records. I want to be able to go to a record by number, not just by stepping through.

In the database is a non auto incrementing key field "ID_Number" which holds consecutive 4 digit integers starting at 1000  ( a hangover from a flat file database originally started in the mid '80's). Unused ID numbers originally were intentionally left blank. The ID's are of customers

With the dataset populated with all records I want to be able to choose one by ID for editing (and eventually choose by string searching of other fields, but first steps...)

As the ID's are never going to get above 4 digits (after 15 years we are still only at 2000+) I would like to enter the numbers into a text box, stop at 4 digits, then do the linear translation from ID_Number to Data Set row number and call  Me.ShowCurrentRecord() But I am not sure how to code to check the key presses into the text box then exit on the 4th (having validated both for being numeric and within ID number range). I assumed I would need to use the textChanged event.

I have made a text box and a "Go" button to go to a specific record via the ID Number, which does work (most of the time), but want to lose the "Go" button step.  

I defined the intCount as a Private integer at the head of the containing form, just under the Class line, and the m_DataAdapter.Fill line is in the form load event with the other connection code.

Don't yet understand question 5!

I presume that I can reset the counter as part of the textChanged event code.

Just for info, this is a learning exercise to develop routines to select a customer address and relevant (from many) contact details from (eventually) 2 or more tables by joining, for use in other routines and/or database editing.  I figured I should learn how to connect to, retrieve and display records first, before I start to try complex selection and manipulation.  I did do a little reading into VB6 & VBA a few years ago and this is a continuation of that.  I have built menu navigation that works, now I am trying to code the routines I need, using as a structural model a turnkey DOS Basic application I reprogrammed over a number of years.

Hope this explains it a bit better

Bob LearnedCommented:
By the way, since you have 2008 Express, you might want to think about upgrading to 2010 Express. I believe that .NET 4.0 framework is a much more significant upgrade over 2008.

"Don't yet understand question 5! "


' Bind TextBox1 to FirstName column of the Employees table
TextBox1.DataBindings.Add("text", dv, "FirstName")

' Bind TextBox2 to LastName column of the Products table
TextBox2.DataBindings.Add("text", dv, "LastName")

Open in new window

Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

chrisatworkAuthor Commented:
Thanks for the info.  I have been reading & researching - I hate having to work without really knowing what I am doing.  I have several new queries as a result of the weekend work and will post new questions in due course.

In the meantime, still haven't figured out how to program the TextChanged event to process the input when it reaches 4 validated numeric characters to translate that into a row number for display of the relevant record in the local dataset.

In the click event on a test using a go button, I took the 4 digit string, extracted the numeric with CInt, subtracted the constant offset from the entered ID number to produce an actual row number then applied this to show that row record (much in the same way as the single stepping buttons moved through the dataset (perfectly).  My method sometimes produced ambiguous results - off by one or two records - and I couldn't see, by debugging, why this should be.

So a clue how to do the TextChanged event would be much appreciated!
Bob LearnedCommented:
Hmmm...let's try this:

1) String.Length function gives you the length of a string.

2) TextBox.Text is a string

3) You can check the length in the TextChanged event to see if it meets your max length criteria.

Does that help?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chrisatworkAuthor Commented:
Thanks for the pointer to the appropriate function (the book was silent here...)

Onto the next (inevitable) question....
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.