Put another way: How to effectively have a form's textbox be bound when
browsing existing records, yet set to an expression when in data entry mode?
I have prior relational db experience, but starting my first Access (2007)
project. Thanks for any advice, RonL
Private Sub UpdateGeneratedField()
Me.GeneratedFieldName = Me.Field1 & "-" & Me.Field2 & "-" & Me.Field3
In the afterupdate event for each of the fields that make up the
generated field, do the following:
Call UpdateGeneratedField
I would recommend some data validation in the UpdateGeneratedField
procedure and/or the after update events for each field.
One other note, if you only want this field to be automatically filled
out and never edited directly by the user, you can set the form fields
locked property to true.
HTH
If you had
=fld1 & fld2 & fld3
as the control source, and fld2 was not filled in, it might not look/be
correct. You could have a function
=GetCombined()
and have
Function GetCombined()
IF not isnull(fld1) and not isnull(fld2) And not isnull(fld3) then
GetCombined = fld1 & fld2 & fld3
endif
End Function
It should automatically update. However, if it doesn't, do something
like is the field name is CalcedField
Me.CalcedField.Requery
in the afterupdate events of fld1..fld3.
Yes I'll do some data validation and disable the (bound) control derived
from the expression.
Thank you both!
(FWIW, the derived field is to be used as a unique "catalog id," [hopefully
eventually to appear on a website if my wife's hobby-business takes off.
This db is for her startup, and as a prototype for a content driven website
if that becomes warranted.] The uniqueness of the value should be
guaranteed because the PK is part of the string. I still gotta think though
whether it should change at all if she edits an existing record. If I
understand my reading so far, it is possible to distinguish in code whether
the current record is "existing" or "new.")
-RonL