Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2004
    Location
    California
    Posts
    502

    Unanswered: Compile error: Expect Identifier

    Going nuts here . . .

    When I compile this I get the dreaded Compile error: Expected Identifier on [ClosePrice] As String) As Double

    I'm at a loss . . .

    Code:
    Option Compare Database
    
    Public Function MedianOfRst(RstName As String, [ClosePrice] As String) As Double
         'This function will calculate the median of a recordset. The field must be a number value.
         Dim MedianTemp As Double
         Dim RstOrig As Recordset
         Set RstOrig = tblhistorical2012.OpenRecordset(RstName, dbOpenDynaset)
         RstOrig.Sort = ClosePrice
         Dim RstSorted As Recordset
         Set RstSorted = RstOrig.OpenRecordset()
         If RstSorted.RecordCount Mod 2 = 0 Then
              RstSorted.AbsolutePosition = (RstSorted.RecordCount / 2) - 1
              MedianTemp = RstSorted.Fields(ClosePrice).Value
              RstSorted.MoveNext
              MedianTemp = MedianTemp + RstSorted.Fields(ClosePrice).Value
              MedianTemp = MedianTemp / 2
         Else
              RstSorted.AbsolutePosition = (RstSorted.RecordCount - 1) / 2
              MedianTemp = RstSorted.Fields(ClosePrice).Value
         End If
         MedianOfRst = MedianTemp
    End Function
    thanks . . . Rick

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    I would change to:
    Code:
    Option Compare Database
    Option Explicit
    
    Public Function MedianOfRst(RstName As String, ClosePrice As String) As Double
    Have a nice day!

  3. #3
    Join Date
    Mar 2004
    Location
    California
    Posts
    502

    Option Explicit

    Thanks Sinndho . . .

    However it had no effect.

    I still get the Expected Identifier on [ClosePrice] As String) As Double

    What else could it possibly be?

    Thanks . . . Rick

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    remove the square brackets
    this is a function declaration, so its using VB the square brackets notation is for column or table names within SQL
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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