Split statement error

B

Bill

Below is a simple function wherein the compiler is
complaining that there's a syntax error in the Split
statement. Clearly, that is not the case. So what's
the problem? (I was just starting to code the
function when the syntax error came up.)

Private Function FormatNewName(InStr) As String
Dim arrParse() As String

arrParse = Split(InStr, "--")

End Function
 
J

John W. Vinson

Below is a simple function wherein the compiler is
complaining that there's a syntax error in the Split
statement. Clearly, that is not the case. So what's
the problem? (I was just starting to code the
function when the syntax error came up.)

Private Function FormatNewName(InStr) As String
Dim arrParse() As String

arrParse = Split(InStr, "--")

End Function

IIRC Split() returns a Variant array, not a String. Try dimming arrParse as
Variant.

You're also not specifying a return value for the function - are you intending
to return a value, an array, or what?
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/Forums/en-US/accessdev/
http://social.answers.microsoft.com/Forums/en-US/addbuz/
and see also http://www.utteraccess.com
 
S

Stuart McCall

Bill said:
Below is a simple function wherein the compiler is
complaining that there's a syntax error in the Split
statement. Clearly, that is not the case. So what's
the problem? (I was just starting to code the
function when the syntax error came up.)

Private Function FormatNewName(InStr) As String
Dim arrParse() As String

arrParse = Split(InStr, "--")

End Function

Instr is the name of a built-in function in VBA. Change the name of your
parameter to (say) strInstr.
 
B

Bill

Jeez! Am I out to lunch or what!!!
Of course InStr is a builtin function. My goodness,
I just used it 4 times in the sub that invoked
the function I had just begun to code..........
man I'm loosing it!

Bill
 
D

David-W-Fenton

IIRC Split() returns a Variant array, not a String. Try dimming
arrParse as Variant.

Nope. It returns an array of strings, according to the Help file.

The problem is that InStr() is a function and you're confusing the
compiler. The argument should be renamed and the data type
specified:

Private Function FormatNewName(strInput As String) As String
 
D

David-W-Fenton

Jeez! Am I out to lunch or what!!!
Of course InStr is a builtin function. My goodness,
I just used it 4 times in the sub that invoked
the function I had just begun to code..........
man I'm loosing it!

Also, you should specify the data type of the parameter declaration.
It has to be a string (though a Variant would work, it allows
passing Nulls, which would error out).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top