Results 1 to 5 of 5
  1. #1
    George is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2012
    Posts
    295

    Null value not responding in VBA Code

    Good Day All,

    Can anyone help me to understand why the Null reference is not being acknowledged in the following module?

    [HTML
    Private Sub Errors_Click()

    Dim MonthDate As String



    If Me.Combo7.Column(0) = Null Then
    MsgBox "Enter a MonthYear value"
    End If

    End Sub][/HTML]

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    you dont check null that way, use:

    if IsNull(me.combo7) then

  3. #3
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,128
    Or perhaps its an empty (zero length) string which isn't the same thing

    Try this which cover nulls & ZLS:
    Code:
    If Nz(Me.Combo7.Column(0),"") = "" Then
    but if column(0) is the bound column it can be omitted
    Code:
    If Nz(Me.Combo7,"") = "" Then
    BTW this line isn't used in the sub so should be deleted
    Code:
    Dim MonthDate As String

    As its in a sub, its out of scope anywhere else
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  4. #4
    George is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2012
    Posts
    295
    Thanks. Its working now.

  5. #5
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    FYE (for your edification),

    Nothing is equal to NULL, not even NULL.

    In the immediate window, if you enter

    ? 1 = 1 , the result will be TRUE

    If you enter
    ?Null = Null, the result is NULL

    That is why there is an IsNull() function...... to check if a value is null.

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

Similar Threads

  1. Help with code - need an if null statement
    By NikoTheBowHunter in forum Access
    Replies: 4
    Last Post: 06-08-2017, 08:07 AM
  2. Replies: 5
    Last Post: 06-05-2017, 02:18 PM
  3. Replies: 9
    Last Post: 06-28-2016, 10:12 AM
  4. Replies: 2
    Last Post: 10-05-2012, 07:52 AM
  5. Null Date control code problem
    By DanW in forum Forms
    Replies: 2
    Last Post: 11-10-2009, 03:13 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