-
Newbie Function Compile Error
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
[vba]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
[/vba]
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:
[vba] getDetails (var1, var2) 'this calls a function to get the details from a worksheet that matches the value in textBox1[/vba]
Thanks in advance.
-
the Function procedure will return a value. you need to put the return value to a variable
[VBA]x = getDetails(var1)[/VBA]
-
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?
-
then create it as Sub procedure if you don't want to return a value..
-
Knowledge Base Approver
The King of Overkill!
VBAX Master
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
-
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.
-
Get rid of the brackets in the function call or use the word "Call" before it.
-
mosley, omit the parenthesis in getDetails
[VBA]
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
[/VBA]
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules