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

Instr and Mid function ERROR 1

Status
Not open for further replies.

BrockLanders

Programmer
Dec 12, 2002
89
US
Hi
On this site I have found a similar example of what I am trying to accomplish but cannot seem to get it to work properly. I have an Access 2000 table with a field called CARRIER that has similar text values. An example of one of the values in the field is: PILOT (014789526).
In my query, I am trying to create a calculated field, called MyNumber, that only returns the value inside the parenthesis. So for the above example, the field MyNumber would return 014789526.
I have the following code for my calculated field, but keep getting #Error in the MyNumber field for every record.

MyNumber: IIf(nz(InStr(1,[CARRIER],"PILOT"))>0,Mid([CARRIER],InStr(1,[CARRIER],"(")+1,InStr(InStr(1,[CARRIER],")")+1,[CARRIER]," ")-(InStr(1,[CARRIER],")")+1)),"")

I believe the syntax is correct, but it just set up wrong. Any ideas?
 
Give this expression a try and see if it works.

IIf(Nz(InStr(1, [CARRIER], "Pilot")) > 0, Mid([CARRIER], InStr(1, [CARRIER], "(") + 1, (InStr(1, CARRIER], ")") - InStr(1, [CARRIER], "(")) - 1), " ")

Paul
 
Yep, that worked exactly. I see what you did now. Thanks much
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top