Hi,
You cannot assign a predetermined Array, even if it has the right
dimensions. You can only assign (use on the left side of the equal sign) an
un-determined (redim -able) array.
When you comment out (the valid line)
TextBoxGetLine = result()
which indicated which result is to be returned by your function, your
function STILL RETURNS an array, because of its header (signature):
Public Function TextBoxGetLine( ....arguments... ) As String()
note the As String(). It should be As String without parenthesis, to
return just ONE single string, not an array of string.
When a function is meet, VBA creates a variable with the name of the
function. Here, VBA creates a variable TextBoxGetLine As String(). That
variable is an array of string, and CAN accept the instruction
TextBoxGetLine = result()
since it is redim-able. If you comment it out, you just get a redim-able
array as result. The problem is not there, but it is when you try to
capture the result in your ***CALLING*** code:
myVariable(index) = TextBoxGetLine( ... )
So, either remove the () in the function signature (AND return JUST ONE
STRING), either keep your function as it is, and make your variable a
redim-able variable, in your CALLING code (and do NOT use a index):
myRedimable = TextBoxGetLine( ... )
and not
myRedimable(index) = TextBoxGetLine( ... )
either, finally, make your variable, in you calling code, as VARIANT rather
than as STRING (but that means you just move the problem to somewhere else
in your code, I think).
Hoping it may help,
Vanderghast, Access MVP