Results 1 to 3 of 3
  1. #1
    Alex Motilal is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Nov 2008
    Location
    Coimbatore, India
    Posts
    192

    Question Error in Function

    Hi Everybody,



    The following function returns 0 as average transport rate per bale:

    Public Function GetAvgBlTrspRate(HeapNumber As Integer) As Double
    Dim MyString As String
    MyString = "SELECT (Sum([tblBaleShiftingDelivery]![balesShifted]*[tblBaleShiftingDelivery]![transpRtForShifting]))/(Sum([tblBaleShiftingDelivery]![balesShifted])) AS AvgTraspPerBale "
    MyString = MyString & "FROM tblHeap INNER JOIN (tblPressing INNER JOIN tblBaleShiftingDelivery ON tblPressing.pressingID = tblBaleShiftingDelivery.lotNo) ON tblHeap.heapID = tblPressing.heapGenerated "
    MyString = MyString & "WHERE (((tblHeap.heapID)=[HeapNumber]));"
    GetAvgBlTrspRate = MySring
    End Function

    Can anyone point out what mistake I am making?

    With thanks
    Alex

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    First of all, you are just building an SQL statement string, you aren't actually running a query. Running a SELECT query in VBA requires opening a recordset.

    Second, I am surprised it returns anything. You declare the function as Double but then set it to a string variable. Also, the variable is misspelled in the last line. Put 'Option Explicit' line in the module header and misspellings like that will be revealed.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Alex Motilal is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Nov 2008
    Location
    Coimbatore, India
    Posts
    192
    Thanks June7 for pointing out the mistake.

    Regards,
    Alex

Please reply to this thread with any new information or opinions.

Similar Threads

  1. VBA - Using GetObject function - get error.
    By jsbotts in forum Programming
    Replies: 7
    Last Post: 10-10-2011, 07:51 AM
  2. aggregate error due to function
    By boutwater in forum Access
    Replies: 2
    Last Post: 09-26-2011, 03:39 PM
  3. Silly error on a simple function call - help
    By allenjasonbrown@gmail.com in forum Programming
    Replies: 5
    Last Post: 06-10-2011, 01:23 PM
  4. Compile error. Sub of function not defined
    By plavookins in forum Reports
    Replies: 7
    Last Post: 04-22-2011, 10:15 AM
  5. an aggregate function error message
    By newtoAccess in forum Queries
    Replies: 1
    Last Post: 11-27-2010, 05:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums