Results 1 to 5 of 5
  1. #1
    NikoTheBowHunter is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2017
    Posts
    58

    Help with code - need an if null statement

    hi guys, with the help of another user on here I have been able to come up with the following code:



    Private Sub Enter_New_Note_Click()
    Me.[Notes History] = Format(Date, "mm/dd/yyyy") & " | " & Me.Text138 & "<BR>" & Me.[Notes History]
    Me.Text138 = Null
    End Sub

    Could someone be so kind to write me a "if null cancel else" statement so that if the text box is null it doesn't add a new note? I honestly have no idea how one would code an if statement as coding is beyond my current skill set.

    cheers

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    which textbox? Enter_New_Note? Notes History? Text138?

    basically the principle would be

    Code:
    if not isnull(name of field to which you are referring) then
        Me.[Notes History] = Format(Date, "mm/dd/yyyy") & "   |   " & Me.Text138 & "<BR>" & Me.[Notes History]
        Me.Text138 = Null
    end if

  3. #3
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    And to just give some info, (IF,Then,Else) statements are not really that difficult or mysterious and are used often in VBA code and also in queries. Basically you have a condition that will test for True or False and you can do something if either of those conditions are met and skip the part that is not met. You can also nest IF statements inside each other to do more complex things. If you are going to be working in Access more, it is a good concept to learn.

    IF ...condition... Then
    (If condition is TRUE, Do something)
    Else
    (If condition is FALSE, Do something)
    End If


  4. #4
    NikoTheBowHunter is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2017
    Posts
    58
    It would be for Text138
    thank you both for the information, with that in hand im sure I can get this figured out. if not ill be back

  5. #5
    NikoTheBowHunter is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2017
    Posts
    58
    this was basically suppose to be a simple little database for me and 2 other coworkers so we could update our inventory as needed without having to track it in 3 different spots. this is the first database I have ever created and probably will be the last haha. which really sucks is after all this work, in 6 months it will no longer be needed :/ but never know might convert it over to track something else.

    and it seems to work, thanks for the help! heres how it looks:
    Code:
    Private Sub Enter_New_Note_Click()
    If Not IsNull(Text138) Then
    Me.[Notes History] = Format(Date, "mm/dd/yyyy") & "   |   " & Me.Text138 & "<BR>" & Me.[Notes History]
    Me.Text138 = Null
    End If
    End Sub

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

Similar Threads

  1. Handling NULL with IIF statement
    By robbeh in forum Queries
    Replies: 7
    Last Post: 01-27-2016, 11:50 AM
  2. SQL Statement to find records with a Null date?
    By IncidentalProgrammer in forum Programming
    Replies: 4
    Last Post: 01-27-2015, 08:30 AM
  3. How to handle null in SQL statement
    By ultimateguy in forum Programming
    Replies: 21
    Last Post: 08-15-2014, 10:48 AM
  4. Access VBA statement to check for Null entries
    By tim_tims33 in forum Access
    Replies: 4
    Last Post: 01-24-2012, 12:19 PM
  5. Replies: 12
    Last Post: 12-11-2011, 05:04 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