Using uncommitted values

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.
 
B

Beetle

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).
 
N

NKK

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.
 
B

Beetle

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
 

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