Results 1 to 9 of 9
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    Examining content of a text box

    I have a text box that has as its ControlSource:



    Code:
    =DSum("Debit","QSelects","[bxHighlight]=True")
    Since DSum returns Null if no records are returned, ought not the TB be Null as well?

    Code:
            If IsNull(Me.tbTotalDeb3HLt) Then    'Any highlighted transactions?
    Apparently not? Nor, is it Empty and also not zero. Other tests, like what is its Value property result in error "You entered an expression that has no value".

    I realize I could solve this by simply running the ControlSource DSum in code to test for its value, but what's the fun in that?

    So, what should the test statement be?

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Or just use he NZ() function?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    If you mean this:
    Code:
    If Nz(Me.tbTotalDeb3HLt) = 0 Then
    Then no, error "You entered an expression that has no value"

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    No, NZ() the DSum()
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Like I indicated in my OP that running the DSum in code works fine, but why/how to examine the vale of the TB bound to the DSum.
    Code:
    If IsNull(DSum("Debit", "QSelects", "[bxHighlight]=True")) Then

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Hmm,

    I added a textbox control with source of
    Code:
    =DSum("Amount","TestTransactions","ID=0")


    Then added
    Code:
    Private Sub cmdTest_Click()
    If IsNull(Me.TxtDsum) Then
        MsgBox "Null"
    Else
        MsgBox "Not Null"
    End If
    End Sub
    and I get null.?

    Change the ID to 2 (which does exist) I get the amount and I get Not Null

    So no idea why it does not work for you?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Likewise! My original code was exactly as you've coded in your example and posted in the OP. Why the DSum return doesn't propagate the current value of the TB only leaves be to believe that perhaps a few copy/paste operations during report design view left a few TB's corrupted?

  8. #8
    Join Date
    Apr 2017
    Posts
    1,681
    Quote Originally Posted by GraeagleBill View Post
    If you mean this:
    Code:
    If Nz(Me.tbTotalDeb3HLt) = 0 Then
    Then no, error "You entered an expression that has no value"
    This will always return False for you, as default second parameter for Nz() is an empty STRING!
    Instead you must use Nz(Me.tbTotalDeb3HLt,0)

  9. #9
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    as default second parameter for Nz() is an empty STRING!
    Only when Nz is used in a query; otherwise the return data type is decided by the whether the context determines it should be Null or ZLS.

    The DSum function should return Null if there are no records that satisfy the criteria so not sure why a test for Null would not result in Null unless you're summing numbers that are text data type. Here's some tests I did with a calculated textbox on a form and directly on the table. Note: not my db so don't mind the wonky names.

    TABLE
    ?DSum("[Point Value]","[Attendance Log]","EmployeeID=1234")
    4
    ?TypeName(DSum("[Point Value]","[Attendance Log]","EmployeeID=1234"))
    Double
    ?DSum("[Point Value]","[Attendance Log]","EmployeeID=123") << no such record with 123
    Null

    TEXTBOX (with criteria 123)
    ?TypeName(forms![Attendance Log1].Text175.value)
    Null
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Accessing content of text box in ribbon
    By JAPA1972 in forum Access
    Replies: 2
    Last Post: 01-15-2019, 12:28 PM
  2. Replies: 16
    Last Post: 12-08-2017, 01:41 PM
  3. Viewing content of long text cells
    By mglevicky in forum Access
    Replies: 3
    Last Post: 01-23-2017, 09:38 AM
  4. Reports positioning boxes with text content
    By pierre86 in forum Reports
    Replies: 2
    Last Post: 09-15-2013, 01:05 PM
  5. Replies: 1
    Last Post: 08-13-2013, 09:39 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