Consulting

Results 1 to 9 of 9

Thread: Newbie Function Compile Error

  1. #1
    VBAX Newbie
    Joined
    Mar 2007
    Posts
    4
    Location

    Arrow 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.

  2. #2
    VBAX Tutor gnod's Avatar
    Joined
    Apr 2006
    Posts
    257
    Location
    the Function procedure will return a value. you need to put the return value to a variable

    [VBA]x = getDetails(var1)[/VBA]

  3. #3
    VBAX Newbie
    Joined
    Mar 2007
    Posts
    4
    Location
    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?

  4. #4
    VBAX Tutor gnod's Avatar
    Joined
    Apr 2006
    Posts
    257
    Location
    then create it as Sub procedure if you don't want to return a value..

  5. #5
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    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

  6. #6
    VBAX Newbie
    Joined
    Mar 2007
    Posts
    4
    Location
    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.

  7. #7
    VBAX Contributor moa's Avatar
    Joined
    Nov 2006
    Posts
    177
    Location
    Get rid of the brackets in the function call or use the word "Call" before it.
    Glen

  8. #8
    VBAX Tutor gnod's Avatar
    Joined
    Apr 2006
    Posts
    257
    Location
    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]

  9. #9
    VBAX Newbie
    Joined
    Mar 2007
    Posts
    4
    Location
    That worked. Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •