Solved

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

Posted on 2004-03-24
3
213 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
Comment Utility
What is the type of  Phone Field ?  Number or Text
0
 
LVL 3

Accepted Solution

by:
pamboo earned 50 total points
Comment Utility
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
Comment Utility
Thanks, Works Great!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
VBA color chart bars 12 64
count7 challenge 12 66
array11 challenge 16 50
Looking for example pivot year code used in Y2K 4 46
A short article about a problem I had getting the GPS LocationListener working.
This is about my first experience with programming Arduino.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
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…

763 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