View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Datasort Datasort is offline
external usenet poster
 
Posts: 50
Default Leave cell value untouched if Custom Function errors

You will need to put error testing into the function. something like ... on
error goto

Then you will need to test to make sure the error is a DB error. You can
find this out buy testing the Err.number.

in the error section set the function to equal n/a (or 0 if you are
returning a number)

Put an if or case statement to test with error:

if err.numer = ???? then
FunctionName = "N/A"
else
msgbox "Unknown error:" & err.decription
end if

Good Luck,

Stewart Rogers

"StephenBrook" wrote:

I have a custom function that uses arguments from the user's worksheet to
find data in an external Access database using ADO, then return it to the
relevant cell. It works fine, but I want to be able to ensure that the custom
function leaves the cell value *untouched* (rather than returning an error
value) if the VBA cannot make the connection to the Access database (e.g. if
the user can't access the database for some reason).

I've tried using Application.Caller to get the cell's original value, but
this doesn't seem to work. Can anyone help?

Thanks,

SB