Results 1 to 5 of 5
  1. #1
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276

    How To Add Dsum To Existing VBA code

    How can I add the following to the code mentioned below.



    =DSum("SBalance","001AAFSleBal")
    The Text Box Name is SleTBal where DSum value will Show.



    CODE:


    Private Sub cboDateFrom_LostFocus()
    If IsNull(DLookup("[SBalance]", "[001BBA]", "IsNull([SBalance]) = FALSE")) = False Then
    OpenBalance.Value = DLookup("[SBalance]", "[001BBA]", "IsNull([SBalance]) = FALSE")
    Else
    OpenBalance.Value = 0
    End If
    End Sub

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Dlookup returns a value , NOT a true/false (unless your field is true/false). SBalance is numeric.

    DLookup("[SBalance]", "[001BBA]", "Not IsNull([SBalance])"))

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Your Dlookup DLookup("[SBalance]", "[001BBA]", "IsNull([SBalance]) = FALSE") is guaranteed to give you the correct result only if there is only one record in [001BBA] where [SBalance] is not Null. Otherwise it is going to give you the first Non-Null value it finds.

    Do you know for sure there is only one non-Null value of SBalance?

  4. #4
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    How can I add the following to the code mentioned

    =DSum("SBalance","001AAFSleBal")


    The Text Box Name is SleTBal where DSum value will Show.

  5. #5
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    me!SletBal = DSum("SBalance","001AAFSleBal") is the statement to use. Be aware that it will return Null if there are no values for SBalance that are not Null.

    Where you put it in the code depends on under what conditions you need it.

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

Similar Threads

  1. Adding loop to existing code
    By smithdam in forum Modules
    Replies: 21
    Last Post: 03-30-2015, 06:54 AM
  2. Gathering data via Outlook using existing VBA code
    By Monterey_Manzer in forum Programming
    Replies: 1
    Last Post: 07-03-2012, 06:29 PM
  3. Replies: 11
    Last Post: 05-23-2012, 08:42 AM
  4. Replies: 4
    Last Post: 05-18-2011, 03:24 PM
  5. Replies: 7
    Last Post: 04-15-2011, 08:46 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