Using uncommitted values

  • Thread starter Thread starter NKK
  • Start date Start date
N

NKK

I have a form that is bound to a table and I would like to use that form for
data entry. There are 4 fields, three text fields and one combo box. I
would like for the value of the third text box to be derived from the values
of the other two text boxes. I have the code that will created the derived
text value, I just need to know how to get it into the third text box and
then save the record. BTW...the field the third text box is bound to is the
primary key for the table. Any nudge in the correct direction would be
appreciated! Thanks.
 
If the value of Field C is derived from the values of Field A and
Field B, then Field C isn't really necessary. You can make Field A
and Field B a composite PK for the table, and then concatenate
the values in a calculated query field/form control for display purposes
(the concantenated value would not be stored in the table).
 
I see what you are saying, however there are foreign keys in several other
tables based on field C, so I really need to store the value of field C.
 
Well, if you're going to do it, I would lock the control for Field C
(the PK field) so users can't accidentally overwrite it, then in the
form's Before Update event use code like;

Private Sub Form_BeforeUpdate (Cancel As Integer)

If Me.Newrecord Then
Me![FieldC] = Me![FieldA] + Me![FieldB]
End If

End Sub
 
Back
Top