Whether you need to use code or not depends on three things:
1. The Zile being bound to a field in the form's underlying table.
2. The Expirare control also being bound to a field in the form's
underlying table.
3. If both of the above are true then on your needing to be able to
manually change the value of the Expirare control after its been calculated
on the basis of the other two values.
If 1 and 2 are True but 3 isn't, i.e. the value of the Expirare control for
each record will always be the value of data + the number of months in the
Zile control then:
You don't need, and should not have, an Expirare field in the underlying
table, but compute the value in an unbound control, or a computed column in a
query, with no VBA code needed at all. In your form for instance the
ControlSource property of an unbound control would be:
=DateAdd("m", Nz([Zile],0), [Data])
The Nz function is necessary to, return a zero if Zile is Null, otherwise
the expression would raise an error.
If on the other hand Zile is an unbound control, with no corresponding Zile
field in the underlying table then you do need to 'push' the value into the
Expirare control with code. I'd suggest the AfterUpdate event procedure of
the Zile control rather than a separate button, with code like this:
Me.[Expirare] = DateAdd("m", Nz(Me.[Zile],0), Me!.Data])
If you are unfamiliar with entering code in event procedures this is how
its done - forgive me if I'm teaching my grandmother to suck eggs:
Select the control in form design view and open its properties sheet if its
not already open. Then select the AfterUpdate event property in the
properties sheet. Click on the 'build' button; that's the one on the right
with 3 dots. Select 'Code Builder' in the dialogue, and click OK. The VBA
window will open at the event procedure with the first and last lines already
in place. Enter the above line of code between these two existing lines.
Ken Sheridan
Stafford, England