access vba - What's wrong with my VBA code (I'm getting runtime error 9) -


i've looked around , found "runtime error 9 subscript out of range" error has arrays. however, i'm not sure how interpret answers i've found best suite code.

i have simple function wrote pull first , last names out of field, found field had few nulls in , tried compensate changing string variant decleration.

i've gotten work without error similar code... not code.

my code follows:

    function flastname(byval lnin variant) variant     dim astrfullname() string     if isnull(lnin)         flastname = null     else         redim astrfullname(2) 'this new concept me... not sure if need         astrfullname = split(lnin, ",")         flastname = astrfullname(0)      end if end function 

thanks in advance insights , assistance.

edit: found issue array doesn't null value in of name fields... thought following line fix that:

if isnull(lnin)     flastname = null 

but apparently wrong.
have advice on i've found far?

you dont need redim ... , dont have dim array.

function flastname(byval lnin variant) variant     dim astrfullname     if isnull(lnin)         flastname = null     else         astrfullname = split(lnin, ",")         flastname = astrfullname(0)     end if end function 

ps: assuming lnin contain comma separated string ... else may have put check.


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -