By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,325 Members | 1,881 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,325 IT Pros & Developers. It's quick & easy.

Calling a module function from a form - Compile error!

P: 4
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:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmd_generoi_Click()
  2.  
  3. Dim instr As String
  4. Dim motor As String
  5. Dim muu1 As String
  6. Dim muu2 As String
  7.  
  8. instr = instru_help.text
  9. motor = moot_help.text
  10. muu1 = muu1_help.text
  11. muu2 = muu2_help.text
  12.  
  13.  
  14. If instr <> "" then
  15.     replaceAliases.replaceAliases(False,instr)
  16. End If
  17.  
  18.  
  19. If muu1 <> "" Then
  20.     replaceAliases.replaceAliases (False,muu1)
  21. End If
  22.  
  23. If muu2 <> "" Then
  24.     replaceAliases.replaceAliases (False,muu2)
  25. End If
  26.  
  27. End Sub
  28.  
Oct 13 '06 #1
Share this Question
Share on Google+
5 Replies


100+
P: 143
Post the code for your function.
Oct 13 '06 #2

MMcCarthy
Expert Mod 10K+
P: 14,534
In access you don't need to refer to the module name when calling a function just the function name.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmd_generoi_Click()
  2.  
  3. Dim instr As String
  4. Dim motor As String
  5. Dim muu1 As String
  6. Dim muu2 As String
  7.  
  8. instr = instru_help.text
  9. motor = moot_help.text
  10. muu1 = muu1_help.text
  11. muu2 = muu2_help.text
  12.  
  13.  
  14. If instr <> "" then
  15. replaceAliases(False,instr)
  16. End If
  17.  
  18.  
  19. If muu1 <> "" Then
  20. replaceAliases (False,muu1)
  21. End If
  22.  
  23. If muu2 <> "" Then
  24. replaceAliases (False,muu2)
  25. End If
  26.  
  27. End Sub
  28.  
  29.  
Oct 14 '06 #3

P: 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
Expand|Select|Wrap|Line Numbers
  1.  Dim instr As String 
into
Expand|Select|Wrap|Line Numbers
  1.  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...

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

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmd_generoi_Click()
  2.  
  3. Dim instr As String
  4. Dim motor As String
  5. Dim muu1 As String
  6. Dim muu2 As String
  7.  
  8. instr = instru_help.text
  9. motor = moot_help.text
  10. muu1 = muu1_help.text
  11. muu2 = muu2_help.text
  12.  
  13.  
  14. If instr <> "" then
  15. replaceAliases(False,instr)
  16. End If
  17.  
  18.  
  19. If muu1 <> "" Then
  20. replaceAliases (False,muu1)
  21. End If
  22.  
  23. If muu2 <> "" Then
  24. replaceAliases (False,muu2)
  25. End If
  26.  
  27. End Sub
  28.  
  29.  
Oct 16 '06 #4

MMcCarthy
Expert Mod 10K+
P: 14,534
InStr is a function in access and therefore an illegal name. It was assuming you wanted to call the function.



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
Expand|Select|Wrap|Line Numbers
  1.  Dim instr As String 
into
Expand|Select|Wrap|Line Numbers
  1.  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...
Oct 16 '06 #5

P: 4
Makes sense. Strange that the given error message didn't quite point to that direction, though...

InStr is a function in access and therefore an illegal name. It was assuming you wanted to call the function.
Oct 16 '06 #6

Post your reply

Sign in to post your reply or Sign up for a free account.