PDA

View Full Version : Newbie Function Compile Error



mosley
03-21-2007, 08:28 AM
Hi I am a newbie, and have a question. I am messing around with creating forms and such (in Excel 2003). But while working with a function I get the following error:

Compile Error:
Expected: =

This is my code
Private Sub OptionButton1_Change()
If OptionButton1.Value = True Then
clearDetails 'this clears the textboxes in the form
getDetails (var1) 'this calls a function to get the details from a worksheet and populate various text boxes in my form. It passes one variable.
End If
End Sub

Function getDetails (temp1)
'this is the code that searches thru a worksheet for the "temp" value and places various values into textboxes in my form
End Function


This works fine. But now I want to pass two variables to the function. When I change the code to call the function to the following I get the above mentioned error:

getDetails (var1, var2) 'this calls a function to get the details from a worksheet that matches the value in textBox1
Thanks in advance.

gnod
03-21-2007, 08:51 AM
the Function procedure will return a value. you need to put the return value to a variable

x = getDetails(var1)

mosley
03-21-2007, 09:05 AM
I am not sure I understand. I dont want the function to return a value. I want it to populate textboxes.

What am I missing here?

gnod
03-21-2007, 09:12 AM
then create it as Sub procedure if you don't want to return a value..

mvidas
03-21-2007, 09:14 AM
A function doesnt need to return a value, I'm guessing the error is caused because the getdetails function only has (temp1) as an argument, and you're trying to pass it 2 arguments.

If that is not the case (you've changed the arguments to be (temp1, temp2), you're going to have to post the whole getdetails function

mosley
03-21-2007, 09:16 AM
mvidas: I thought so.

But I should have said when I add the second variable to the call for the function, I add it into the function itself also. So thats not the problem.

Just for the heck of it I tried to call a bogus function with two variables I get the same error.

moa
03-21-2007, 09:30 AM
Get rid of the brackets in the function call or use the word "Call" before it.

gnod
03-21-2007, 09:34 AM
mosley, omit the parenthesis in getDetails


Private Sub OptionButton1_Change()
If OptionButton1.Value = True Then
clearDetails 'this clears the textboxes in the form
getDetails var1, var2
End If
End Sub

Function getDetails(temp1, temp2)
'this is the code that searches thru a worksheet for the "temp" value and places various values into textboxes in my form
End Function

mosley
03-21-2007, 10:29 AM
That worked. Thanks!