Solved

Binding One DB Field, To Multiple Controls (50 Points)

Posted on 2004-03-24
3
233 Views
Last Modified: 2010-04-17
In Visual Basic.Net: I have an Access DB, and i want to Bind a Phone Field Stored As XXX XXX XXXX no spaces. I want to bind it to 3 sperate text boxes without using an invisable intermediate textbox. is this possible? a small code snippet would also be appreciated if possible. Thanks
0
Comment
Question by:RHopkinson
  • 2
3 Comments
 
LVL 3

Expert Comment

by:pamboo
ID: 10674958
What is the type of  Phone Field ?  Number or Text
0
 
LVL 3

Accepted Solution

by:
pamboo earned 50 total points
ID: 10675228
I suggest it might be a Text field since number type cannt hold large values (10 digit values) .

Considering u have declared the phone field as text , just try the below .

U bind all the 3 textboxex to the same field

Say dt is ur DataTable

Me.TextBox1.DataBindings.add("Text",dt,"Phone_Field")
Me.TextBox2.DataBindings.add("Text",dt,"Phone_Field")
Me.TextBox3.DataBindings.add("Text",dt,"Phone_Field")

In the TextChanged event of above 3 textbox do the below

'First text box should contain the digits 8 to 10
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

 If  Me.TextBox1.Text <> vbNullString Then

  If Me.TextBox1.Text.Length > 7 then
    Me.TextBox1.Text = Mid(Me.TextBox1.Text,1,Me.TextBox1.Text.Length-7)
  else
    Me.TextBox1.Text = VbNullString ' Or  Me.TextBox1.Text = "000"
  End If

 End If

End Sub

Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged

 If  Me.TextBox2.Text <> vbNullString Then

  If TextBox2.Text.Length <= 4 then
     Me.TextBox2.Text = VbNullString ' Or  Me.TextBox1.Text = "000"
  If TextBox2.Text.Length <= 7 and TextBox2.Text.Length >= 5 then
     Me.TextBox2.Text = Mid(Me.TextBox2.Text,1,Me.TextBox1.Text.Length-4)
  Else  If TextBox2.Text.Length > 7
     Me.TextBox2.Text = Mid(Me.TextBox2.Text,Me.TextBox1.Text.Length-6,3)
 End If

End Sub

Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
 If  Me.TextBox3.Text <> vbNullString Then
  If TextBox3.Text.Length > 4 then
     Me.TextBox3.Text = Mid(Me.TextBox3.Text,Me.TextBox3.Text.Length-3)
 End If
End Sub

- Rajan
0
 

Author Comment

by:RHopkinson
ID: 10680217
Thanks, Works Great!
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
groupSum6 challenge 6 85
groupNoAdj 7 95
"Black Box" Testing of Control System Software 2 48
SQL Insert parts by customer 12 31
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

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

11 Experts available now in Live!

Get 1:1 Help Now