Connect with Expertise | Find Experts, Get Answers, Share Insights

Allow append data only to memo field

 
Join Date: Mar 2010
Posts: 10
#1: Mar 10 '10
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!

✓ answered by missinglinq

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 (IndirectDataInput) 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 IndirectDataInput and in the Properties Box set its Caption to “Add New Data.”

Now use this code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub IndirectDataInput_Click()
  2. If IndirectDataInput.Caption = "Add New Data" Then
  3.    TempDataBox.Visible = True
  4.    TempDataBox.SetFocus
  5.    IndirectDataInput.Caption = "Commit Data"
  6. Else
  7.    IndirectDataInput.Caption = "Add New Data"
  8.    If IsNull(Me.CommentsField) Then
  9.       If Len(Me.TempDataBox) > 0 Then
  10.         Me.CommentsField = Me.TempDataBox
  11.         Me.TempDataBox = ""
  12.         TempDataBox.Visible = False
  13.       Else
  14.         TempDataBox.Visible = False
  15.       End If
  16.     Else
  17.       If Len(Me.TempDataBox) > 0 Then
  18.        Me.CommentsField = Me.CommentsField & vbNewLine & Me.TempDataBox
  19.        Me.TempDataBox = ""
  20.        TempDataBox.Visible = False
  21.       Else
  22.        TempDataBox.Visible = False
  23.       End If
  24.  
  25.     End If
  26. End If
  27. 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)>

missinglinq's Avatar
E
C
 
Join Date: Nov 2006
Location: Richmond, Virginia USA
Posts: 3,381
#2: Mar 10 '10

re: Allow append data only to memo field


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 (IndirectDataInput) 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 IndirectDataInput and in the Properties Box set its Caption to “Add New Data.”

Now use this code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub IndirectDataInput_Click()
  2. If IndirectDataInput.Caption = "Add New Data" Then
  3.    TempDataBox.Visible = True
  4.    TempDataBox.SetFocus
  5.    IndirectDataInput.Caption = "Commit Data"
  6. Else
  7.    IndirectDataInput.Caption = "Add New Data"
  8.    If IsNull(Me.CommentsField) Then
  9.       If Len(Me.TempDataBox) > 0 Then
  10.         Me.CommentsField = Me.TempDataBox
  11.         Me.TempDataBox = ""
  12.         TempDataBox.Visible = False
  13.       Else
  14.         TempDataBox.Visible = False
  15.       End If
  16.     Else
  17.       If Len(Me.TempDataBox) > 0 Then
  18.        Me.CommentsField = Me.CommentsField & vbNewLine & Me.TempDataBox
  19.        Me.TempDataBox = ""
  20.        TempDataBox.Visible = False
  21.       Else
  22.        TempDataBox.Visible = False
  23.       End If
  24.  
  25.     End If
  26. End If
  27. 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)>
E
C
 
Join Date: Dec 2009
Location: Denmark
Posts: 548
#3: Mar 10 '10

re: Allow append data only to memo field


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:

Expand|Select|Wrap|Line Numbers
  1. If Me.tb_Input & "" <>"" Then 'Check that something is in field
  2.   'Add the new input the field.
  3.   Me.tb_FullStory="[" & Date() & "]" & vbnewline & _
  4.                   Me.tb_Input & vbnewline & vbnewline & _
  5.                   Me.Tb_FullStory
  6. End If
  7.  
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.
 
Join Date: Mar 2010
Posts: 10
#4: Mar 10 '10

re: Allow append data only to memo field


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

Glad to join!
 
Join Date: Mar 2010
Posts: 10
#5: Mar 12 '10

re: Allow append data only to memo field


These worked great! Thanks!
Reply