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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sytax to delete partial 1

Status
Not open for further replies.

EBee

MIS
Aug 10, 2001
229
US
i need to trim part of a description

DoubleJP-12345 want vba to delete -12345

right now i manualy delete them by using the search and replace in access query. i don't even know how to start. the field name is description and it is always

right(desription,6,"-") . . . . delete them code

search -*
replace

thanks
erwin
 
I don't have Access on this machine or any of my books with me, but I think it would be:

UPDATE MyTable
SET MyTable!Description =
LEFT(MyTable!Description,
INSTR(MyTable!Description, 1, "-") - 1)

Since I can't test this, make sure you look up the LEFT and INSTR functions to make sure that I have the parameteres correct.

Hope that helps... Terry M. Hoey
 
I am getting some error with this code. . . i think i am almost there, i need i to return doubleJp-12345 with just doubleJp. I looked in the book but i can not find a vba that deletes from the "-" the right or capture items from the left of "-"

thanks
erwin

Private Sub Update_data()

Dim db As Database
Dim rs As Recordset


Set db = CurrentDb()
Set rs = db.OpenRecordset("Trial_tbl")

rs.MoveFirst
Do Until rs.EOF

rs.Edit
rs!Description = Left(rs!Description, InStr(rs!Description, 1, "-") - 1)
rs.Update

rs.MoveNext
Loop

MsgBox "done"
End Sub

 
Try changing the following line:

rs!Description = Left(rs!Description, InStr(rs!Description, 1, "-") - 1)

to:

rs!Description = Left(rs!Description, (InStr(rs!Description, "-") - 1)) Terry M. Hoey
 
the code you suggested worked . . .thanks

erwin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top