Using Mid and Find function in Access

psulions83

Board Regular
Joined
Nov 16, 2015
Messages
127
Hi,

I am trying to convert an Excel formula to Access but cannot figure out what will work. I have tried using InStr for the FIND alternative but cannot get it to work.

Excel formula
MID(O2,FIND("%",O2)-1,1)

I feel like I am doing something that is a simple fix but for some reason I cannot work around it.

Any help would be much appreciated.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
myString=MID("YourString",instr("YourString","%")-1,1)
 
Last edited:
Upvote 0
thank you.....that worked great. I thought i performed the function like that before but i guess i messed something up.

In the below formula, any idea why i would ever get #FUNC ! and #ERROR !?

IIf(IsNumeric(Mid([Tbl_Contract]![PayTerm],InStr([Tbl_Contract]![PayTerm],"%")-1,1)),Mid([Tbl_Contract]![PayTerm],InStr([Tbl_Contract]![PayTerm],"%")-1,1)/100,0)
 
Upvote 0
Hi,
You have to be very careful with IIF (or like me, just use it very rarely or never). VBA IIF does not use short circuit evaluation.

This means that the ENTIRE expression is evaluated, including all parts, including your second part that attempts to divide with something that may not be a number, even though you probably don't want that to happen if the first part is false.

In this case, you probably cannot use IIF() this way.
 
Upvote 0
Thats interesting. Thank you for that bit of information. I guess there is no way to suppress this with access then?
 
Upvote 0
When I wrap the IsError function around the MID it makes all the lines that do not have an error zero. Before putting it the lines that should have an answer were right vs the other lines erroring out.
 
Upvote 0
When I wrap the IsError function around the MID it makes all the lines that do not have an error zero. Before putting it the lines that should have an answer were right vs the other lines erroring out.

Is this satisfactory or is it still a problem?
 
Upvote 0
Xenou,

Not really but I found a work around since using IIf statements don't really work well for error handling. Thanks for letting me know about that so I didn't spend 20 hours trying to figure out why it wasn't working!

Thanks
 
Upvote 0
Okay. As a note, you can sometimes just divide your data into the good and the bad (and if necessary the ugly as well):
Code:
SELECT
	(A / B) as DangerousOperation 
FROM 
	Table 
WHERE
	B <> 0

UNION ALL

SELECT
	0 as DangerousOperation 
FROM 
	Table 
WHERE
	B = 0
 
Upvote 0

Forum statistics

Threads
1,221,579
Messages
6,160,616
Members
451,658
Latest member
NghiVmexgdhh

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top