Calling a module function from a form - Compile error!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AkiMatti
    New Member
    • Oct 2006
    • 4

    Calling a module function from a form - Compile error!

    Hi!

    I'm using MS Access 2002 and have troubles calling my function in a module I've created. When I try to even write the call of the function, it instantly gives me an error saying: "Compile Error Expected: (" eventhough I have the '(' in there. Sometimes it expects a '=' symbol instead, wanting me to bind the call to some variable I guess. What should I do? The function I'm calling does not return any parameters.

    Here is my code:

    Code:
    Private Sub cmd_generoi_Click()
    
    Dim instr As String
    Dim motor As String
    Dim muu1 As String
    Dim muu2 As String
    
    instr = instru_help.text
    motor = moot_help.text
    muu1 = muu1_help.text
    muu2 = muu2_help.text
    
    
    If instr <> "" then
        replaceAliases.replaceAliases(False,instr)
    End If
    
    
    If muu1 <> "" Then
        replaceAliases.replaceAliases (False,muu1)
    End If
    
    If muu2 <> "" Then
        replaceAliases.replaceAliases (False,muu2)
    End If
        
    End Sub
  • Tanis
    New Member
    • Mar 2006
    • 143

    #2
    Post the code for your function.

    Comment

    • MMcCarthy
      Recognized Expert MVP
      • Aug 2006
      • 14387

      #3
      In access you don't need to refer to the module name when calling a function just the function name.

      Code:
      Private Sub cmd_generoi_Click()
       
      Dim instr As String
      Dim motor As String
      Dim muu1 As String
      Dim muu2 As String
       
      instr = instru_help.text
      motor = moot_help.text
      muu1 = muu1_help.text
      muu2 = muu2_help.text
       
       
      If instr <> "" then
      replaceAliases(False,instr)
      End If
       
       
      If muu1 <> "" Then
      replaceAliases (False,muu1)
      End If
       
      If muu2 <> "" Then
      replaceAliases (False,muu2)
      End If
       
      End Sub

      Comment

      • AkiMatti
        New Member
        • Oct 2006
        • 4

        #4
        Actually, often when I try to call simply the function name, Access wants to create a new macro or sub, which would be set to call the function. I wonder why is this?

        Strangely, my problem got solved when I changed the name of one of my variables. I just changed
        Code:
         Dim instr As String
        into
        Code:
         Dim instru As String
        and the errors were gone. Still, I didn't even find any variables with the same name. I wonder what cause those errors in the first place...

        Originally posted by mmccarthy
        In access you don't need to refer to the module name when calling a function just the function name.

        Code:
        Private Sub cmd_generoi_Click()
         
        Dim instr As String
        Dim motor As String
        Dim muu1 As String
        Dim muu2 As String
         
        instr = instru_help.text
        motor = moot_help.text
        muu1 = muu1_help.text
        muu2 = muu2_help.text
         
         
        If instr <> "" then
        replaceAliases(False,instr)
        End If
         
         
        If muu1 <> "" Then
        replaceAliases (False,muu1)
        End If
         
        If muu2 <> "" Then
        replaceAliases (False,muu2)
        End If
         
        End Sub

        Comment

        • MMcCarthy
          Recognized Expert MVP
          • Aug 2006
          • 14387

          #5
          InStr is a function in access and therefore an illegal name. It was assuming you wanted to call the function.



          Originally posted by AkiMatti
          Actually, often when I try to call simply the function name, Access wants to create a new macro or sub, which would be set to call the function. I wonder why is this?

          Strangely, my problem got solved when I changed the name of one of my variables. I just changed
          Code:
           Dim instr As String
          into
          Code:
           Dim instru As String
          and the errors were gone. Still, I didn't even find any variables with the same name. I wonder what cause those errors in the first place...

          Comment

          • AkiMatti
            New Member
            • Oct 2006
            • 4

            #6
            Makes sense. Strange that the given error message didn't quite point to that direction, though...

            Originally posted by mmccarthy
            InStr is a function in access and therefore an illegal name. It was assuming you wanted to call the function.

            Comment

            Working...