Allow append data only to memo field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rhonda6373
    New Member
    • Mar 2010
    • 35

    Allow append data only to memo field

    Hello,

    I have a user that wants to allow data entry in a memo field. He does not want to allow changes to existing text in the same field, but only allow entry of new text. He would also like any existing text to be viewable as well.

    Does anyone know of code that could accomplish this?

    Thank you in advance!
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    Working with medical/legal records, I've used this hack for a number of years. A second, unbound textbox (TempDataBox) is used to enter the data into. This textbox is originally hidden, and when the command button (IndirectDataIn put) is clicked, it appears. Data is entered, and when the command button (now captioned “Commit Data”) is clicked again, the entered data is added to the memo field.

    Now, in this example, there are two memo fields, but only one is bound, since the other memo field is simply a temporary holding area. The memo field is also locked so that all data entry has to be done thru the temporary textbox.

    TempDataBox is unbound, and in the Property Box its Visible Property is set originally set to No. I place mine side by side with CommentsField so the user can refer to what's currently in the CommentsField section while entering new notes.

    CommentsField is bound to the underlying table/query, and its Locked Property is set to Yes.

    Place a command button on the form. Name it IndirectDataInp ut and in the Properties Box set its Caption to “Add New Data.”

    Now use this code:

    Code:
    Private Sub IndirectDataInput_Click()
    If IndirectDataInput.Caption = "Add New Data" Then
       TempDataBox.Visible = True
       TempDataBox.SetFocus
       IndirectDataInput.Caption = "Commit Data"
    Else
       IndirectDataInput.Caption = "Add New Data"
       If IsNull(Me.CommentsField) Then
          If Len(Me.TempDataBox) > 0 Then
            Me.CommentsField = Me.TempDataBox
            Me.TempDataBox = ""
            TempDataBox.Visible = False
          Else
            TempDataBox.Visible = False
          End If
        Else
          If Len(Me.TempDataBox) > 0 Then
           Me.CommentsField = Me.CommentsField & vbNewLine & Me.TempDataBox
           Me.TempDataBox = ""
           TempDataBox.Visible = False
          Else
           TempDataBox.Visible = False
          End If
          
        End If
    End If
    End Sub
    Replace CommentsField with the actual name of your textbox and keep the rest of the control names as given.

    Welcome to Bytes!

    Linq ;0)>

    Comment

    • TheSmileyCoder
      Recognized Expert Moderator Top Contributor
      • Dec 2009
      • 2322

      #3
      My solution would be to have a unbound text box, and then when user clicks a button "Add to existing text" the text is transferred.
      Assuming your bound textbox is called tb_FullStory and we call the unbound textbox tb_Input I would use something like this:

      Code:
      If Me.tb_Input & "" <>"" Then 'Check that something is in field
        'Add the new input the field.
        Me.tb_FullStory="[" & Date() & "]" & vbnewline & _
                        Me.tb_Input & vbnewline & vbnewline & _
                        Me.Tb_FullStory
      End If
      I added some Date info to the textbox, but you can just remove that if its not usefull for your application. I also made it so the new text is placed before the old text, but you can also just switch that aroud.

      Comment

      • rhonda6373
        New Member
        • Mar 2010
        • 35

        #4
        These are great ideas. Thank you so much and they are easy answers to understand. I will try these out.

        Glad to join!

        Comment

        • rhonda6373
          New Member
          • Mar 2010
          • 35

          #5
          These worked great! Thanks!

          Comment

          Working...