Hi,
I have column with data that looks like similar to this:
M1302_RISK_OF_PRSR_ULCR
I need to slit out the first part in each row, when the first letter in the string is M. Otherwise it would remain the same. When the first letter starts with "M" it will always be 5 characters before the _. Each cell is differnt and may be much longer than this example. The one consistent thing is that the info I need is always at the beginning of the string.
Thanks!
Leesha
Spliting info
-
- Administrator
- Posts: 78446
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Spliting info
Let's say the field is named MyField.
The expression you need would be
IIf([Left([MyField],1)="M",Mid([MyField],6),[MyField])
The expression you need would be
IIf([Left([MyField],1)="M",Mid([MyField],6),[MyField])
Best wishes,
Hans
Hans
-
- BronzeLounger
- Posts: 1487
- Joined: 05 Feb 2010, 22:25
Re: Spliting info
Thanks Hans!
I must be doing something wrong because I'm getting an erorr "the expression you entered contains invalid syntax, or you need to enclose your text in quotes.
This is my query expression:
M0Answer:IIf([Left([form_location],1)="M",Mid([form_location],6),[form_location])
Thanks
Leesha
I must be doing something wrong because I'm getting an erorr "the expression you entered contains invalid syntax, or you need to enclose your text in quotes.
This is my query expression:
M0Answer:IIf([Left([form_location],1)="M",Mid([form_location],6),[form_location])
Thanks
Leesha
-
- Administrator
- Posts: 78446
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Spliting info
Sorry, a typo. There shouldn't have been a [ before Left:
M0Answer:IIf(Left([form_location],1)="M",Mid([form_location],6),[form_location])
M0Answer:IIf(Left([form_location],1)="M",Mid([form_location],6),[form_location])
Best wishes,
Hans
Hans
-
- BronzeLounger
- Posts: 1487
- Joined: 05 Feb 2010, 22:25
Re: Spliting info
Thanks! That took care of the error. When I ran the code it returned the info after the M0 piece (I'm sure my request didn't make sense). So instead of returning M1302_RISK_OF_PRSR_ULCR it gave me RISK_OF_PRSR_ULCR. I expreimented with the code by changing "Mid" to Left and changed the 6 to a 5 and it worked!!! I couldn't have done that if it hadn't been all of these years with your teaching me!!
Thanks,
Leesha
Thanks,
Leesha
-
- Administrator
- Posts: 78446
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Spliting info
I had interpreted your request differently, but I'm glad you were able to modify the formula!
Best wishes,
Hans
Hans
-
- BronzeLounger
- Posts: 1487
- Joined: 05 Feb 2010, 22:25
Re: Spliting info
Only because I have such a patient teacher!!!
Thanks again,
Leesha
Thanks again,
Leesha