Calculated default value

  • Thread starter Thread starter Michael Beckinsale
  • Start date Start date
M

Michael Beckinsale

Hi all,

Pls can somebody tell me how to do the following:

I need to include a database text field in a form which initially defaults
to a concatenation of 2 or more text fields from the same table ONLY when
adding a new record. The user must be permitted to overwrite the default
value offered and save back to the database field.

If viewing or amending existing records the form must read the existing
value NOT re-calculate the default.

All comments / suggestions gratefully accepted.

Regards

Michael Beckinsale
 
Hi, Michael. You can use the OnCurrent form event to test
whether you're at a new record; then write the value you
want to your control. If you're not on a new record,
nothing will happen. Something like:

Private Sub Form_Current()
Dim intnewrec As Integer
intnewrec = Me.NewRecord
If intnewrec = True Then
Me![YourControlName] = Me![ctl1] + Me![ctl2]
End If
End Sub
 
Hi Kevin,

Many thanks the code you gave worked a treat.

I had to make a slight adj and trigger the macro with the "OnGetFocus" event
because if the record is new then the preceding fields would be blank
resulting in a Null value, which is not allowed in that field.

Again many thanks,

Regards
Kevin Sprinkel said:
Hi, Michael. You can use the OnCurrent form event to test
whether you're at a new record; then write the value you
want to your control. If you're not on a new record,
nothing will happen. Something like:

Private Sub Form_Current()
Dim intnewrec As Integer
intnewrec = Me.NewRecord
If intnewrec = True Then
Me![YourControlName] = Me![ctl1] + Me![ctl2]
End If
End Sub
-----Original Message-----
Hi all,

Pls can somebody tell me how to do the following:

I need to include a database text field in a form which initially defaults
to a concatenation of 2 or more text fields from the same table ONLY when
adding a new record. The user must be permitted to overwrite the default
value offered and save back to the database field.

If viewing or amending existing records the form must read the existing
value NOT re-calculate the default.

All comments / suggestions gratefully accepted.

Regards

Michael Beckinsale
 
Back
Top