Trying to write an expression.

J

John C

I am trying to write an expression that will populate a field in a report so
that when a value is selected it will display the date and time that the
value was selected.
 
R

Rick B

=now()

Can't tell you how to apply this because you do not give enough detail. If
you want a field to fill in with the current date and time when some other
field is filled in, you would put code in the "change" event for that second
field. Then, anytime the "second" field is changed, the code would run.
The code would look something like...

Me!somefieldname = Now()


Hope that helps,

Rick B
 
J

John C

Sorry I will add more detail. I have a form set up for user to input data.
I have a field called "status" that has two choices either "Open" or
"closed". The way it is set up now is when a user enters data into the form
for a record there is a timestamp that goes into a field call "Date/Time
Opened". I have another field that is called "Date/Time Closed". What I
would like to do is when a user selects closed in the "status" field I would
like a time stamp to auto populate the "Date/Time Closed" field.
 
R

Rick B

Then do what I said and place code behind the "change" event of the status
field.

Your code would need an IF statement to say IF STATUS = "CLOSED" THEN
DTCLOSED=Now().


Rick B
 
J

John C

Thanks Rick

Rick B said:
Then do what I said and place code behind the "change" event of the status
field.

Your code would need an IF statement to say IF STATUS = "CLOSED" THEN
DTCLOSED=Now().


Rick B
 
J

John C

Now I am having an issue becuase the Status field can either be open or
Closed and the code is blowing up when every I try to select one of them. I
am guessing I need to code it so that when the Status Field reads "Open" it
puts that timestamp into the Date Time Opened field and when Status reads
"Closed" it put the Timestamp in the Date Time Closed Field. Does anyone
happen to know the code that would do this?
 
J

John Vinson

Then do what I said and place code behind the "change" event of the status
field.

I'd suggest the AfterUpdate event instead - the Change event fires *at
every keystroke*, and does not fire if the user leaves the actual
value unchanged (say by backspacing or hitting the Escape key).

John W. Vinson[MVP]
 
J

John Vinson

Now I am having an issue becuase the Status field can either be open or
Closed and the code is blowing up when every I try to select one of them. I
am guessing I need to code it so that when the Status Field reads "Open" it
puts that timestamp into the Date Time Opened field and when Status reads
"Closed" it put the Timestamp in the Date Time Closed Field. Does anyone
happen to know the code that would do this?

Use the AfterUpdate event:

Private Sub Status_AfterUpdate()
Select Case Me!Status
Case "Open"
Me![Date Time Opened] = Now
Case "Closed"
Me![Date Time Closed] = Now
Case Else
<do something appropriate>
End Select
End Sub

John W. Vinson[MVP]
 
Top