Calculated default value

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
 
K

Kevin Sprinkel

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
 
M

Michael Beckinsale

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
 

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