MS Access Forum / General 2 / March 2007
Extract numbers
|
|
Thread rating:  |
Pietro - 24 Mar 2007 12:48 GMT Hi all, I have a query that contains a field(subject) that always has data like this: SM# 2-1009579390 - New Industry report
I need to make anthother field in the query to extract only the numbers of this field,knowing that the length of this number may differ from record to record. If it's possible,i need to extract only the numbers that come after 2-
Thanx
Joseph Meehan - 24 Mar 2007 14:38 GMT > Hi all, > I have a query that contains a field(subject) that always has data [quoted text clipped - 7 lines] > > Thanx Are they always (100%) in the format XXXXXXNNNN...
This is they all will have exactly six characters (letters, numbers, spaces or other characters) followed directly by the numbers you want and nothing else?
 Signature Joseph Meehan
Dia 's Muire duit
John W. Vinson - 24 Mar 2007 16:32 GMT >Hi all, > I have a query that contains a field(subject) that always has data like [quoted text clipped - 5 lines] >record. > If it's possible,i need to extract only the numbers that come after 2- ?Mid([subject], InStr([subject], "2-") + 2, InStr(InStr([subject], "2-"), [subject], " ")-6)
will do it if the part before the number is always 6 bytes long.
John W. Vinson [MVP]
Pietro - 28 Mar 2007 02:49 GMT Thank you for your answer.., but actually the problem is that the part before the number is NOT always 6 bytes long,so can i do it or not ?
> >Hi all, > > I have a query that contains a field(subject) that always has data like [quoted text clipped - 12 lines] > > John W. Vinson [MVP] John W. Vinson - 28 Mar 2007 05:50 GMT >Thank you for your answer.., >but actually the problem is that the part before the number is NOT always 6 >bytes long,so can i do it or not ? You can use another InStr() to calculate the position - I'm too sleepy tonight to figure it out, but if you type Ctrl-G to open the VBA editor, hit F1 to get VBA help, and search for InStr you'll find detailed specs for how the function works.
John W. Vinson [MVP]
Pietro - 28 Mar 2007 11:52 GMT I tried to do this,but i got lost,so please sleep well for now,i'm waiting for your help when you wake up :)
> >Thank you for your answer.., > >but actually the problem is that the part before the number is NOT always 6 [quoted text clipped - 6 lines] > > John W. Vinson [MVP] John W. Vinson - 29 Mar 2007 01:33 GMT >I tried to do this,but i got lost,so please sleep well for now,i'm waiting >for your help when you wake up :) sorry... not going to be able to get time for this anytime soon, I'm getting ready for a 1200 mile drive and will be offline for a week.
I'd suggest you start a new thread with the expression so far.
John W. Vinson [MVP]
Al Campagna - 29 Mar 2007 13:59 GMT Pietro, Try, =Mid([subject],InStr([subject],"2-")+2,(InStr([subject]," - N")-2)-InStr([subject],"2-")) If this doesn't work, cut and paste your expression exactly when you reply.
 Signature hth Al Campagna . Candia Computer Consulting . Candia, NH USA Microsoft Access MVP http://home.comcast.net/~cccsolutions
"Find a job that you love, and you'll never work a day in your life."
>I tried to do this,but i got lost,so please sleep well for now,i'm waiting > for your help when you wake up :) [quoted text clipped - 9 lines] >> >> John W. Vinson [MVP] Pietro - 29 Mar 2007 15:12 GMT Hi "Al Campagna", I got an Error#
=Mid([subject],InStr([subject],"2-")+2,(InStr([subject]," - N")-2)-InStr([subject],"2-"))
> Pietro, > Try, [quoted text clipped - 14 lines] > >> > >> John W. Vinson [MVP] Al Campagna - 29 Mar 2007 17:48 GMT Pietro, The calculation is correct, and tested. It will return the number portion... of "SM# 2-1009579390 - New Industry report"... no matter how many characters precede the "2-"
1. Use your own object names in the calculation. I used [Subject] as an example. Use the name of your field that you are parsing in the calculation. 2. The name of the calculated field can not be the same as any element in the calculation itself. If you named the calculated field [Subject], the that's why you're getting an #Error. Call the Field something like "ParseSM", or "ExtractedSMNo", etc...
Other than that, there is something about your setup that you have not informed us of...
 Signature hth Al Campagna . Candia Computer Consulting . Candia, NH USA Microsoft Access MVP http://home.comcast.net/~cccsolutions
"Find a job that you love, and you'll never work a day in your life."
> Hi "Al Campagna", > I got an Error# [quoted text clipped - 21 lines] >> >> >> >> John W. Vinson [MVP]
|
|
|