preserving results of calculations in forms

J

John C

Hi I need to keep the result of this control
=IIf([chkbx]=Yes,Date(),Null) to be preserved. At the moment this only
displays the current date, I need the the result to be preserved when the
[chkbx] check box is checked and not updated unless it is unchecked.
 
J

John Vinson

On Fri, 31 Mar 2006 15:29:01 -0800, John C <John
Hi I need to keep the result of this control
=IIf([chkbx]=Yes,Date(),Null) to be preserved. At the moment this only
displays the current date, I need the the result to be preserved when the
[chkbx] check box is checked and not updated unless it is unchecked.

You'll need to do this in a different manner. The Control Source of a
textbox or other control can *either* be a fieldname in the Form's
recordsource, *or* an expression - it can't be both!

I'd suggest using VBA code in the AfterUpdate event of the checkbox
control. If you want the textbox txtDate to contain today's date if
the user checks chkbx, and to be cleared if they uncheck it, view the
checkbox's Properties; click the ... icon by the AfterUpdate property;
choose Code Builder; and edit the code to

Private Sub chkbx_AfterUpdate()
If Me!chkbx Then
Me!txtDate = Date
Else
Me!txtDate = Null
End If
End Sub


John W. Vinson[MVP]
 
J

John C

This dosn't seem to work. The result is always 30/12/1899 if checked or
29/12/1899 unchecked. Any further advice appriciated!

John Vinson said:
On Fri, 31 Mar 2006 15:29:01 -0800, John C <John
Hi I need to keep the result of this control
=IIf([chkbx]=Yes,Date(),Null) to be preserved. At the moment this only
displays the current date, I need the the result to be preserved when the
[chkbx] check box is checked and not updated unless it is unchecked.

You'll need to do this in a different manner. The Control Source of a
textbox or other control can *either* be a fieldname in the Form's
recordsource, *or* an expression - it can't be both!

I'd suggest using VBA code in the AfterUpdate event of the checkbox
control. If you want the textbox txtDate to contain today's date if
the user checks chkbx, and to be cleared if they uncheck it, view the
checkbox's Properties; click the ... icon by the AfterUpdate property;
choose Code Builder; and edit the code to

Private Sub chkbx_AfterUpdate()
If Me!chkbx Then
Me!txtDate = Date
Else
Me!txtDate = Null
End If
End Sub


John W. Vinson[MVP]
 
J

John C

Ok Thank, You this does work. Just some of my syntax needed sorting thank you.

John Vinson said:
On Fri, 31 Mar 2006 15:29:01 -0800, John C <John
Hi I need to keep the result of this control
=IIf([chkbx]=Yes,Date(),Null) to be preserved. At the moment this only
displays the current date, I need the the result to be preserved when the
[chkbx] check box is checked and not updated unless it is unchecked.

You'll need to do this in a different manner. The Control Source of a
textbox or other control can *either* be a fieldname in the Form's
recordsource, *or* an expression - it can't be both!

I'd suggest using VBA code in the AfterUpdate event of the checkbox
control. If you want the textbox txtDate to contain today's date if
the user checks chkbx, and to be cleared if they uncheck it, view the
checkbox's Properties; click the ... icon by the AfterUpdate property;
choose Code Builder; and edit the code to

Private Sub chkbx_AfterUpdate()
If Me!chkbx Then
Me!txtDate = Date
Else
Me!txtDate = Null
End If
End Sub


John W. Vinson[MVP]
 
Top