Using Date() in code

  • Thread starter Thread starter john
  • Start date Start date
J

john

I am trying to us Date() in the following Access 2000 code:

Private Sub cboStatus_AfterUpdate()
If Me.cboStatus = "Closed" Then
Me!txtDateCompleted = Date()
End If
End Sub

...but when I attempt to save the routine, the () dissapears. Then when
I run the code, access generates an error stating it's unable to find a
field name called Date. Using Now() works but I just need the date.
Besides, if I use Now() and then attempt to edit this field, it
displays the entire date and time, even though the format and input
mask is set to Medium Date.

Any assitance is appreciated.
 
I am trying to us Date() in the following Access 2000 code:

Private Sub cboStatus_AfterUpdate()
If Me.cboStatus = "Closed" Then
Me!txtDateCompleted = Date()
End If
End Sub

..but when I attempt to save the routine, the () dissapears. Then when
I run the code, access generates an error stating it's unable to find a
field name called Date. Using Now() works but I just need the date.
Besides, if I use Now() and then attempt to edit this field, it
displays the entire date and time, even though the format and input
mask is set to Medium Date.

Any assitance is appreciated.

In VBA there is no need for the parenthesis in Date().
Date in VBA = Date() in Access.
That's why the VBA editor strips them.
This is also true if you use Now().

Is cboStatus a Combo Box?
Is the column that displays the word "Closed" the bound column?
If so, then:

If Me!cboStatus = "Closed" Then
Me!txtDateCompleted = Date
End If

If you still have a problem with this, then I suggest you also check
your references for any that are marked Missing.

Open any module in Design view (or click Ctrl + G).
On the Tools menu, click References.
Click to clear the check box for the type library or object library
marked as "Missing:."

An alternative to removing the reference is to restore the referenced
file to the path specified in the References dialog box. If the
referenced file is in a new location, clear the "Missing:" reference
and create a new reference to the file in its new folder.

See Microsoft KnowledgeBase articles:
283115 'ACC2002: References That You Must Set When You Work with
Microsoft Access'
Or for Access 97:
175484 'References to Set When Working With Microsoft Access' for
the correct ones needed,
and
160870 'VBA Functions Break in Database with Missing References' for
how to reset a missing one.

For even more information, see
http://www.accessmvp.com/djsteele/AccessReferenceErrors.html
 
Thanks for the quick response Fred.

Yes, cboStatus is a Combo Box.

The column that that displays the word "Closed" comes from a value
list.

As mentioned, using Date by itself generates the error I mentioned, but
using Now() works and the () do not dissapear.

Already checked for a missing references and there are none.

If anyone else has a suggestion it would be appreciated..

Thanx.
 
Thanks for the quick response Fred.

Yes, cboStatus is a Combo Box.

The column that that displays the word "Closed" comes from a value
list.

As mentioned, using Date by itself generates the error I mentioned, but
using Now() works and the () do not dissapear.

Already checked for a missing references and there are none.

If anyone else has a suggestion it would be appreciated..

Thanx.

Does your table have a field named Date, or do you have a form control
named Date? If so, Access may be getting confused - rename them.

John W. Vinson[MVP]
 
There was a reference in the object browser to something called Date in
one of the subforms so I deleted that subform and created a new one but
the problem still persists.
 
do you have the Name AutoCorrect function turned OFF in your database? if
not, try turning it off (from the menu bar, select Tool | Options | General
tab) and the compacting the db.

if the Date function still doesn't work, try creating a new, empty database
and immediately turning off Name AutoCorrect. then import all the objects
from your database, compact it, and try using the Date function in your
procedure again.

hth
 
Back
Top