Date returns null

G

Guest

I have a procedure which has the following code, which should allow me to
record today date.

Private Sub Form_AfterUpdate()

If Me!Status = "Completed" Then
Me!Datecompleted = date
End if

End

In the intermediate window

? me!staus = completed
? Me!datecompleted = null

I have checked these posts and date seems to be the standard for returning
todays date. Does anyone have any thoughts on why this returns a null.

Thanks Ronnie
 
G

Guest

Thanks for the reply Rick.

If I set

Me!Datecompleted =date()

as you state, VB when it move to the next line make this
Me!Datecompleted = date

I suppose that's the problem, but I am not sure what is causing it to do that

Thanks Ronnie
 
S

Steve Conway

Hi Ronnie,

I *believe* it is normal for the () to be removed when used in VBA. If
Me!Datecompleted = date is not giving you today's date, the first thing to
check is - make sure you are not using the word date as any field/control
names. This can cause access and you some major problems. I always
disambiguate all references to Date() by using:

Me!Datecompleted = VBA.Date

see if that works for you.

HTH
Steve C
 
G

Guest

Thanks Steve

There is no reference to date for any fields/control names. I have also
tried your vba.date and still datecompleted returns a Null. I am baffled.

Thanks Ronnie
 
D

Dan Artuso

Hi,
With any code module open, press ctl-G,
this will bring up the immediate window.
Type in:

?Date

hit return, does it show you today's date?
 
D

Dan Artuso

Hi,
Okay, what is Me!DateCompleted refering to?
Do you mean it to refer to a control on your form or a field in the
form's underlying recordset?
Do your control and field have the same name?
If so, try changing the control name to:
txtDateCompleted
and then refer to the control in your code (I assume here that the control
is bound to the field).
So...

If Me!Status = "Completed" Then
Me.txtDateCompleted= date
End if

Then, step through the code to make sure you actually enter the If statement.
 
G

Guest

Now I am baffled. I have removed the if statement from the procedure and
simply put in

Me.txtDateCompleted= date and still does not work. The date does appear in
date box but it looks like something is blocking the update
 
D

Dan Artuso

Hi,
Do you mean to say that the date appears in the text box, but when you close the form
or navigate to another record, the record is not saved?
What is the record source for your form? A query I presume?
Is the date field the only field that is not getting saved?
Your txtDateCompleted text box is bound to a field in your query?
 
D

Dirk Goldgar

Ronnie said:
I have a procedure which has the following code, which should allow
me to record today date.

Private Sub Form_AfterUpdate()

If Me!Status = "Completed" Then
Me!Datecompleted = date
End if

End

In the intermediate window

? me!staus = completed
? Me!datecompleted = null

I have checked these posts and date seems to be the standard for
returning todays date. Does anyone have any thoughts on why this
returns a null.

Thanks Ronnie

One question: Are you trying to set the value of DateCompleted on the
record that was just updated? The form's AfterUpdate event is too late
for that -- the record has already been saved. You may be setting
DateCompleted on some other record entirely.
 
G

Guest

Thanks Dirk. You were correct. I was trying to update a record that had
already been saved.

Ronnie
 

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