making a field editable once it has data.

A

ART

I have a form in which multiple users will update data, however there are 4
fields which i need for them to be able to add new data and not overwrite
what is existing. Example: They user 1 may type a comment in the field. user
2 may later need to add additional comments but not change what was
previously entered.
Is this possible? again i only want this for a few fields not all on on the
form.
If not possible, can i simply make these fields uneditable once they are no
longer null?
I tried using a macro to setvalue to lock once the focus is lost but upon
closing and reopening the form the property resets to unlock.
what am i doing wrong?
thanks
 
J

John W. Vinson

I have a form in which multiple users will update data, however there are 4
fields which i need for them to be able to add new data and not overwrite
what is existing. Example: They user 1 may type a comment in the field. user
2 may later need to add additional comments but not change what was
previously entered.
Is this possible? again i only want this for a few fields not all on on the
form.


Well... it can be done, but it's not really a good design. If you have one
record with multiple comments, a better design would be to have two tables in
a one to many relationship; the second table would have a foreign key to the
primary key of your table, a Memo field for the comment (text field if your
comments will never exceed 255 characters), and probably a UserID field to
record who made the comment and a date/time field defaulting to Now() to
record when the comment was made. You could use a Subform to enter the
comments.
If not possible, can i simply make these fields uneditable once they are no
longer null?

You can set the control's Enabled property to No and its Locked property to
Yes in the Form's Current event if it is not Null.

You can't really allow a user to append a new comment and at the same time
*prevent* them from editing the existing comment. You can make it a bit easier
to add data to the existing field with code like this in the textbox's
GotFocus event:

Private Sub txtComment_GotFocus()
Me.txtComment.SelStart = Len(Me!txtComment & "")
End Sub

to put the cursor at the end of the data. This won't prevent the user from
manually backspacing or clicking into the existing data, though.
 
N

NetworkTrade

or use JV's advice in a modified way; add an unbound text box for 'Add A
Comment'

and then AfterUpdate of this new box put in a little code that appends it to
the existing comment; something like

Dim Comment as String
Comment = me.ExistingComment
Comment = Comment & me.AddComment
me.ExistingComment=Comment

now that I think of it you probably have to unlock that ExistingComment
field then relock it

this keeps the user out of the actual comment box....
 
J

John W. Vinson

or use JV's advice in a modified way; add an unbound text box for 'Add A
Comment'

and then AfterUpdate of this new box put in a little code that appends it to
the existing comment; something like

Dim Comment as String
Comment = me.ExistingComment
Comment = Comment & me.AddComment
me.ExistingComment=Comment

now that I think of it you probably have to unlock that ExistingComment
field then relock it

this keeps the user out of the actual comment box....

Nice! I've never seen it done that way but it would certainly work. You could
even throw in some dividers, e.g.

Comment = Comment & vbCrLf & vbCrLf & Now() & vbCrLf & me.AddComment
 
A

ART

Thank you so much. This logic makes perfect sense. I believe that I can
follow this. I am not very saavy with VBA. Learning as i go. Can you direct
me to a good tutorial for VBA?
thanks again
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top