Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to insert "-" in certain position of records

Status
Not open for further replies.

vc1881

Programmer
Nov 9, 2008
32
0
0
US
Hello, I am using VB.NET 2005 and MS ACCESS 2003

My database contains data in the following format:

1305000248767

I need to insert "-" in several location to obtain the following format

1305-00-024-8767

How do I append the records to insert the "-" at these locations.

Thanks,

Victor
 
You can do it in several ways.
One thing to remember is that the field must be long enough to accept new values.

Try using the Mid function.

Good luck.
 
Can you please send me a small sample with rhe Mid function?

Thanks
 
Try this instead - its a .net string method - there are lots of different ones that are more useful than the traditional visual basic string commands

Dim strwork As String = "1305000248767"
strwork = strwork.Insert(4, "-").Insert(7, "-").Insert(11, "-")
 
Here is an example using the ExecuteNonQuery method:
Code:
Dim cmd1 As New OleDb.OleDbCommand
cmd1.Connection = connection 'change this
cmd1.CommandText = _
	"Update FieldName " & _
	"set FieldName = mid(FieldName ,1,4) + '-' + mid(FieldName ,5,2) + '-' + mid(FieldName ,7,3)  + '-' + mid(FieldName ,10,4)"
cmd1.ExecuteNonQuery()

Make sure that each record has the same length (13).
Good luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top