preserving results of calculations in forms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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]
 
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]
 
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]
 

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

Back
Top