Results 1 to 5 of 5
  1. #1
    jazzy is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Nov 2021
    Posts
    77

    Checking Subform Value on Command Button not working

    when i stop the code it shows me that the [subfrm_Invoice].[Form]![InvoiceCreatedDate] = Null. When i remove the if then statement i can put the current date value in that field. sure its a different way i have to specify the field. Thanks



    Code:
    Private Sub OpenDepositInvoice_Click()If [subfrm_Invoice].[Form]![InvoiceCreatedDate] = Null Then
    [subfrm_Invoice].[Form]![InvoiceCreatedDate] = Date
    End If
    End Sub

  2. #2
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Try IsNull() https://learn.microsoft.com/en-us/of...snull-function

    Code:
    If IsNull([subfrm_Invoice].[Form]![InvoiceCreatedDate]) Then
        [subfrm_Invoice].[Form]![InvoiceCreatedDate] = Date
    End If
    If that doesn't work. Are you more directly referring to a form's control or record source's field? if your referring to a control you may try to test if it's equal to "" (an empty string) rather than compare against null. (untested guess... worth testing though)

    Either way bookmark this handy reference http://access.mvps.org/access/forms/frm0031.htm

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    nothing = null, not even null

    use the isnull function

    If isnull([subfrm_Invoice].[Form]![InvoiceCreatedDate]) Then

    or the nz function


    If nz([subfrm_Invoice].[Form]![InvoiceCreatedDate],0) = 0 Then

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    In Access/VBA, can't compare anything to Null because there's nothing to compare.
    Handle Null as described by CJ.
    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.

  5. #5
    jazzy is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Nov 2021
    Posts
    77
    That was it, thank you

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

Similar Threads

  1. Replies: 21
    Last Post: 01-31-2022, 01:09 PM
  2. Command button to allow edits not working ??????
    By TenOc in forum Programming
    Replies: 16
    Last Post: 12-09-2021, 03:20 PM
  3. Command Button On Subform not working
    By aamer in forum Access
    Replies: 2
    Last Post: 12-21-2019, 05:57 PM
  4. Replies: 1
    Last Post: 09-12-2014, 06:09 AM
  5. Replies: 4
    Last Post: 10-08-2012, 05:33 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