Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weird VBA Expected End of Statement Error

Tags:

vba

ms-access

I started working on creating a custom function in Access 2010, using the VBA Editor, but I keep getting an Expected End of Statement Error.

Here's the code:

Public Function getPayTotal(ByVal StudentID As Long) As Long

Return StudentID

End Function

I have absolutely no idea why this isn't working. The debug keeps sending me back to the Return StudentID line. Am I over looking something incredibly simple?

like image 418
user2004245 Avatar asked Feb 18 '23 04:02

user2004245


1 Answers

Not return:

Public Function getPayTotal(ByVal StudentID As Long) As Long

   getPayTotal = StudentID

End Function

You can call the function like so:

Sub theFunction
   getPayTotal 21

   ''Or
   Call getPayTotal(21)

   ''Or
   r = getPayTotal(21)
End Sub

In other words, be careful with the parentheses.

like image 139
Fionnuala Avatar answered Feb 23 '23 22:02

Fionnuala