Results 1 to 4 of 4
  1. #1
    vicsaccess's Avatar
    vicsaccess is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    451

    sum of Dlookup


    i'm needing a little help. i have a form based on a job with a tab control. one of the tabs has a subform for the different hours by craft that the job will encounter. i have a text box called txttotalcrafthours on my main form to sum the hours of all the crafts associated with the job but i'm running into a compile error:sub or function not defined pointing to my "sum" of the dlookup. any ideals?

    Code:
        Dim x As Integer
        x = SUM(DLookup("Hours", "workquecraftt", "WorkQueID= 'me.WorkQueID.value'"))
        Me.txttotalcrafthours.Value = x

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Aggregate functions work in queries or textboxes, not in VBA.

    Use domain aggregate functions in VBA.

    Concatenate the reference to form control. If WorkQueID is number type field, do not use apostrophe delimiters - they are for text type.

    x = DSum("Hours", "workquecraft", "WorkQueID=" & Me.WorkQueID)

    If this form is Continuous or Datasheet, every record will show the same value in txttotalcrafthours. Should probably put the DSum() in textbox ControlSource.

    What table is the subform bound to?
    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
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Why not use DSum() instead? Your syntax needs work too:

    http://access.mvps.org/access/general/gen0018.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    vicsaccess's Avatar
    vicsaccess is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    451
    thanks both of you, i don't know how you pull this off the top of your heads so fast. changed to DSum inside the text box control source and working great.

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

Similar Threads

  1. DLOOKUP Help
    By UTLee in forum Access
    Replies: 8
    Last Post: 08-29-2013, 09:48 AM
  2. DLookup help
    By mike02 in forum Queries
    Replies: 1
    Last Post: 08-07-2013, 02:29 PM
  3. Dlookup
    By emanual4real in forum Forms
    Replies: 3
    Last Post: 06-19-2013, 03:09 PM
  4. Help with Dlookup
    By taimysho0 in forum Programming
    Replies: 2
    Last Post: 07-07-2012, 03:55 AM
  5. Help with a Dlookup
    By funkygoorilla in forum Programming
    Replies: 1
    Last Post: 01-21-2012, 10:04 AM

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