Results 1 to 5 of 5
  1. #1
    RLehrbass is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2015
    Posts
    102

    Question how would i write this if null function?

    When i close the form, If the company Name field is 'empty' then fill it in with the First and Last name.

    i would think it would be something like this?

    If Null Me![CompanyName] then
    Me![CompanyName] = Me![FirstName] &" "& Me![LastName]
    End If

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    If IsNull(Me!CompanyName) Then
    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
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    You could use the IsNull() function and also check for an empty string ...

    Code:
    If IsNull(Me![CompanyName]) or Me![CompanyName] = "" then
     Me![CompanyName] = Me![FirstName] & " " & Me![LastName]
     End If
    Another approach may be to look for something greater than an empty string. You might want to test the following ...
    Code:
    If Me![CompanyName] > "" then
    else
    Me![CompanyName] = Me![FirstName] & " " & Me![LastName]
     End If

  4. #4
    RLehrbass is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2015
    Posts
    102
    Does this look correct?

    If IsNull (Me!CompanyName) Then
    Me![CompanyName] = Me![FirstName] & " " & Me![LastName]
    End If

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by RLehrbass View Post
    Does this look correct?

    Sometimes controls can contain empty strings so it is a good idea to test for them. Newer versions of Access will do some Black Box stuff and turn fields assigned Empty Strings into Null. However, a control can still = "" (at times)

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

Similar Threads

  1. Replies: 21
    Last Post: 06-25-2013, 09:22 AM
  2. Replies: 8
    Last Post: 09-18-2012, 08:09 AM
  3. Evaluating Null in a Case Function
    By orcinus in forum Programming
    Replies: 8
    Last Post: 05-11-2012, 10:27 AM
  4. Combo is Null Function Help
    By fabian1675 in forum Forms
    Replies: 1
    Last Post: 02-10-2012, 05:57 PM
  5. DLookUp function giving invalid use of null error
    By shubhamgandhi in forum Programming
    Replies: 4
    Last Post: 07-21-2011, 06:04 PM

Tags for this Thread

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