RE: Leave cell value untouched if Custom Function errors

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Datasort (Datasort_at_discussions.microsoft.com)
Date: 10/28/04


Date: Thu, 28 Oct 2004 09:33:06 -0700

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



Relevant Pages

  • Re: if table exist
    ... does any knows how can i check the existence of a table in a ms access database ?i need a sql statement that provide this function. ... Dim tdf As TableDef ... On Error GoTo 0 ...
    (comp.databases.ms-access)
  • Re: Continuing when an Error occurs
    ... remember to reset after (On Error Goto 0). ... If Not fld Is Nothing Then ... > access database. ...
    (microsoft.public.excel.programming)