C
CES
All,
I'm trying to figure out how to deal with the possibility of a null value being passed into a function.
I'm using the following call to a function in an MS Access form "=getFullName([Field])" the problem seems to be if the field does not have a value, I'm receiving an #Error message in the control box ??? - (because I'm passing in an incorrect number of variables into the function) - ??? I know I can use an IIF() on the form control, but I like to figure out how to do it within the module itself.
I know how to suppress the error by using:
On Error Resume Next
On Error GoTo 0.
But I can't figure out how to then work that into an IF statement that tests for an error and if an error occurs, clears the function or if there is no error It does something. I know the answer lies in error handling, but I can't seem to figure out how to correctly coded it. The code below gives you an idea of what I am trying to accomplish, but in no way works.
Thanks in advance. - CES
Public Function getFullName(tmp As String) As String
If Err.Number <> 0 Then
On Error Resume Next
On Error GoTo 0
getFullName = "0"
Else
getFullName = tmp
End Function
I'm trying to figure out how to deal with the possibility of a null value being passed into a function.
I'm using the following call to a function in an MS Access form "=getFullName([Field])" the problem seems to be if the field does not have a value, I'm receiving an #Error message in the control box ??? - (because I'm passing in an incorrect number of variables into the function) - ??? I know I can use an IIF() on the form control, but I like to figure out how to do it within the module itself.
I know how to suppress the error by using:
On Error Resume Next
On Error GoTo 0.
But I can't figure out how to then work that into an IF statement that tests for an error and if an error occurs, clears the function or if there is no error It does something. I know the answer lies in error handling, but I can't seem to figure out how to correctly coded it. The code below gives you an idea of what I am trying to accomplish, but in no way works.
Thanks in advance. - CES
Public Function getFullName(tmp As String) As String
If Err.Number <> 0 Then
On Error Resume Next
On Error GoTo 0
getFullName = "0"
Else
getFullName = tmp
End Function