Results 1 to 6 of 6
  1. #1
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305

    Struggling with command to add/update text field

    I'm struggling with the below code for a command button. The field I'm trying to update is a long text field. Essentially, if the field is blank, I just want the date/comment to go right in, so to speak. But if there's existing text, I want to skip two lines and then put the date/comment.

    I'm not getting any errors, but the field is not updating with the date/comment. For either situation. I'm very new to VBA, so I'm sure that I'm doing these if functions completely wrong. Any suggestions?



    Code:
    Private Sub btnUpdateResolution_Click()On Error GoTo btnUpdateResolution_Click_Err
    
    
        If Me.Resolution = Null Then
        Me.Resolution = Date & ": comment"
        End If
        Me.Dirty = False
    
        If Me.Resolution <> Null Then
        Me.Resolution = Me.Resolution & vbCrLf & vbCrLf & Date & ": comment"
        End If
        Me.Dirty = False
    
        
        Call Form_Current
        
    btnUpdateResolution_Click_Exit:
        Exit Sub
    
    
    btnUpdateResolution_Click_Err:
        MsgBox Error$
        Resume btnUpdateResolution_Click_Exit
    
    
    End Sub

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Do you have a field called "comment"?
    You have a control on a form called resolution.
    How do these fit together?
    I've seen and have used long text fields to store dated comments.
    But I would recommend you use a real table, structured to meet your needs.

  3. #3
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305
    I'm sorry. The 'comment' is what I want added to the field. It's not a field itself.

    I'm basically trying to add '7/26/2022: comment' to the field

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    You cannot use = null in this way you need to use the isnull function

    If Isnull(Resolution) then

  5. #5
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Also, the control is either NULL or not NULL, so there is no need for two tests.
    Try
    Code:
    Private Sub btnUpdateResolution_Click()
       On Error GoTo btnUpdateResolution_Click_Err
    
       If IsNull(Me.Resolution) Then
          Me.Resolution = Date & ": comment"
       Else
          Me.Resolution = Me.Resolution & vbCrLf & vbCrLf & vbCrLf & Date & ": comment"
       End If
       Me.Dirty = False
       
       Call Form_Current
        
    btnUpdateResolution_Click_Exit:
        Exit Sub
    
    btnUpdateResolution_Click_Err:
       MsgBox Error$
       Resume btnUpdateResolution_Click_Exit
    
    End Sub

    This also works
    Code:
    Private Sub btnUpdateResolution_Click()
       On Error GoTo btnUpdateResolution_Click_Err
    
       Me.Resolution = Me.Resolution & IIf(IsNull(Me.Resolution), "", vbCrLf & vbCrLf & vbCrLf) & Date & ": comment"
       Me.Dirty = False
       
       Call Form_Current
        
    btnUpdateResolution_Click_Exit:
        Exit Sub
    
    btnUpdateResolution_Click_Err:
       MsgBox Error$
       Resume btnUpdateResolution_Click_Exit
    
    End Sub

  6. #6
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305
    Quote Originally Posted by ssanfu View Post
    Also, the control is either NULL or not NULL, so there is no need for two tests.
    Try
    Code:
    Private Sub btnUpdateResolution_Click()
       On Error GoTo btnUpdateResolution_Click_Err
    
       If IsNull(Me.Resolution) Then
          Me.Resolution = Date & ": comment"
       Else
          Me.Resolution = Me.Resolution & vbCrLf & vbCrLf & vbCrLf & Date & ": comment"
       End If
       Me.Dirty = False
       
       Call Form_Current
        
    btnUpdateResolution_Click_Exit:
        Exit Sub
    
    btnUpdateResolution_Click_Err:
       MsgBox Error$
       Resume btnUpdateResolution_Click_Exit
    
    End Sub

    This also works
    Code:
    Private Sub btnUpdateResolution_Click()
       On Error GoTo btnUpdateResolution_Click_Err
    
       Me.Resolution = Me.Resolution & IIf(IsNull(Me.Resolution), "", vbCrLf & vbCrLf & vbCrLf) & Date & ": comment"
       Me.Dirty = False
       
       Call Form_Current
        
    btnUpdateResolution_Click_Exit:
        Exit Sub
    
    btnUpdateResolution_Click_Err:
       MsgBox Error$
       Resume btnUpdateResolution_Click_Exit
    
    End Sub
    Thank you!! That worked!

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

Similar Threads

  1. Struggling with a validation rule / before update
    By thompjas in forum Programming
    Replies: 6
    Last Post: 02-19-2015, 07:18 PM
  2. Replies: 2
    Last Post: 06-07-2013, 11:07 AM
  3. Text Box Update After Command Click
    By Joopster in forum Access
    Replies: 3
    Last Post: 02-17-2013, 04:52 PM
  4. Replies: 3
    Last Post: 12-13-2012, 01:51 PM
  5. Replies: 2
    Last Post: 05-05-2010, 02:52 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