PC Review


Reply
Thread Tools Rate Thread

Date() and Time() functions not returning values

 
 
Mark A. Sam
Guest
Posts: n/a
 
      12th Sep 2003
I am using Access2002 and getting errors in this code:

Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset("Order Entry Hold Status Notes",
dbOpenDynaset, dbSeeChanges)
rst.AddNew
rst![OrdID] = Parent.[OrdID]
rst![Date] = Date
rst![Time] = Time()
rst.Update

Run time error 2427. You have entered an expression that has no value.
This means the Date Function and Time function.

I placed a textbox in a form with the ControlSource, =Date() which
displayed the date without a problem

The libraries I am using are:

Visual Basic for Applications
Microsoft Access 10.0 Object Library
Microsoft Access DAO 3.6 Object Library
OLE Automation

Thanks in advance.

God Bless,

Mark A. Sam


 
Reply With Quote
 
 
 
 
Chris
Guest
Posts: n/a
 
      12th Sep 2003
The only thing that I can think if is that it is getting
lost because of the field names being reserved keywords.
Try renaming them: OrderDate and OrderTime.

Else, try rst("Date")

Also, I wouldn't have spaces in the name of the table. If
you need them, try

Dim dbs As DAO.Database
set dbs = CurrentDB
dim rst as DAO.Recodset
set rst = dbs.OpenRecordset("Select * from [Order Entry
Hold Status Notes]")


Chris



>-----Original Message-----
>I am using Access2002 and getting errors in this code:
>
>Dim rst As Recordset
>Set rst = CurrentDb.OpenRecordset("Order Entry Hold

Status Notes",
>dbOpenDynaset, dbSeeChanges)
>rst.AddNew
>rst![OrdID] = Parent.[OrdID]
>rst![Date] = Date
>rst![Time] = Time()
>rst.Update
>
>Run time error 2427. You have entered an expression that

has no value.
>This means the Date Function and Time function.
>
>I placed a textbox in a form with the ControlSource,

=Date() which
>displayed the date without a problem
>
>The libraries I am using are:
>
>Visual Basic for Applications
>Microsoft Access 10.0 Object Library
>Microsoft Access DAO 3.6 Object Library
>OLE Automation
>
>Thanks in advance.
>
>God Bless,
>
>Mark A. Sam
>
>
>.
>

 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      13th Sep 2003
It's possible it's because you're using Date and Time as fields in your
recordset. You should never use reserved words for any of your own objects,
be they table fields, form controls, VBA variables, etc.

And while I realize it's not what you're asking, why are you storing Date
and Time separately? Use a single variable, and store both. It'll make your
WHERE clauses a lot simpler. If you need them separated for some reason,
create a query with computed fields DateValue([MyDateTimeField]) and
TimeValue([MyDateTimeField])

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele


"Mark A. Sam" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I am using Access2002 and getting errors in this code:
>
> Dim rst As Recordset
> Set rst = CurrentDb.OpenRecordset("Order Entry Hold Status Notes",
> dbOpenDynaset, dbSeeChanges)
> rst.AddNew
> rst![OrdID] = Parent.[OrdID]
> rst![Date] = Date
> rst![Time] = Time()
> rst.Update
>
> Run time error 2427. You have entered an expression that has no value.
> This means the Date Function and Time function.
>
> I placed a textbox in a form with the ControlSource, =Date() which
> displayed the date without a problem
>
> The libraries I am using are:
>
> Visual Basic for Applications
> Microsoft Access 10.0 Object Library
> Microsoft Access DAO 3.6 Object Library
> OLE Automation
>
> Thanks in advance.
>
> God Bless,
>
> Mark A. Sam
>
>



 
Reply With Quote
 
Mark A. Sam
Guest
Posts: n/a
 
      13th Sep 2003

"Douglas J. Steele" <(E-Mail Removed)> wrote in message
news:%23%(E-Mail Removed)...
> It's possible it's because you're using Date and Time as fields in your
> recordset. You should never use reserved words for any of your own

objects,
> be they table fields, form controls, VBA variables, etc.


That isn't the issue, although you are correct about using Key Word. I
always place brackets around field names so it has never been a problem for
me.

I tried assigning Date() and Time() to variables with the same result.


> And while I realize it's not what you're asking, why are you storing Date
> and Time separately? Use a single variable, and store both. It'll make

your
> WHERE clauses a lot simpler. If you need them separated for some reason,
> create a query with computed fields DateValue([MyDateTimeField]) and
> TimeValue([MyDateTimeField])



I just personally find it easier to work with when date and time are in
different fields. I don't want to have to parse the values out whenever I
need to reference them.

God Bless,

Mark


 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      13th Sep 2003
The fact that Date() and Time() aren't working by themselves is a pretty
good sign that there are either other objects with those names in your
database, or else you have a References problem.

Check the references first: it's easier.

Open any code module (or open the Debug Window, using Ctrl-G, provided you
haven't selected the "keep debug window on top" option). Select Tools |
References from the menu bar. Examine all of the selected references.

If any of the selected references have "MISSING:" in front of them, unselect
them, and back out of the dialog. If you really need the reference(s) you
just unselected (you can tell by doing a Compile All Modules), go back in
and reselect them.

If none have "MISSING:", select an additional reference at random, back out
of the dialog, then go back in and unselect the reference you just added. If
that doesn't solve the problem, try to unselect as many of the selected
references as you can (Access may not let you unselect them all), back out
of the dialog, then go back in and reselect the references you just
unselected. (NOTE: write down what the references are before you delete
them, because they'll be in a different order when you go back in)

If that doesn't work, then search through all of your code to see whether
you're using Date or Time inappropriate somewhere.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele


"Mark A. Sam" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> "Douglas J. Steele" <(E-Mail Removed)> wrote in message
> news:%23%(E-Mail Removed)...
> > It's possible it's because you're using Date and Time as fields in your
> > recordset. You should never use reserved words for any of your own

> objects,
> > be they table fields, form controls, VBA variables, etc.

>
> That isn't the issue, although you are correct about using Key Word. I
> always place brackets around field names so it has never been a problem

for
> me.
>
> I tried assigning Date() and Time() to variables with the same result.
>
>
> > And while I realize it's not what you're asking, why are you storing

Date
> > and Time separately? Use a single variable, and store both. It'll make

> your
> > WHERE clauses a lot simpler. If you need them separated for some reason,
> > create a query with computed fields DateValue([MyDateTimeField]) and
> > TimeValue([MyDateTimeField])

>
>
> I just personally find it easier to work with when date and time are in
> different fields. I don't want to have to parse the values out whenever I
> need to reference them.
>
> God Bless,
>
> Mark
>
>



 
Reply With Quote
 
Mark A. Sam
Guest
Posts: n/a
 
      13th Sep 2003
Doug,

There doesn't seem to be a reference problem. This code inserts a record on
a subform. I opened the subform itself as a form and the record was
inserted and date and times assigned without a problem.

I renamed the Date and Time fields to Date1 and Time1 and that solved it.

Thanks.

God Bless,

Mark



"Douglas J. Steele" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> The fact that Date() and Time() aren't working by themselves is a pretty
> good sign that there are either other objects with those names in your
> database, or else you have a References problem.
>
> Check the references first: it's easier.
>
> Open any code module (or open the Debug Window, using Ctrl-G, provided you
> haven't selected the "keep debug window on top" option). Select Tools |
> References from the menu bar. Examine all of the selected references.
>
> If any of the selected references have "MISSING:" in front of them,

unselect
> them, and back out of the dialog. If you really need the reference(s) you
> just unselected (you can tell by doing a Compile All Modules), go back in
> and reselect them.
>
> If none have "MISSING:", select an additional reference at random, back

out
> of the dialog, then go back in and unselect the reference you just added.

If
> that doesn't solve the problem, try to unselect as many of the selected
> references as you can (Access may not let you unselect them all), back out
> of the dialog, then go back in and reselect the references you just
> unselected. (NOTE: write down what the references are before you delete
> them, because they'll be in a different order when you go back in)
>
> If that doesn't work, then search through all of your code to see whether
> you're using Date or Time inappropriate somewhere.
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
>
>
> "Mark A. Sam" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >
> > "Douglas J. Steele" <(E-Mail Removed)> wrote in message
> > news:%23%(E-Mail Removed)...
> > > It's possible it's because you're using Date and Time as fields in

your
> > > recordset. You should never use reserved words for any of your own

> > objects,
> > > be they table fields, form controls, VBA variables, etc.

> >
> > That isn't the issue, although you are correct about using Key Word. I
> > always place brackets around field names so it has never been a problem

> for
> > me.
> >
> > I tried assigning Date() and Time() to variables with the same result.
> >
> >
> > > And while I realize it's not what you're asking, why are you storing

> Date
> > > and Time separately? Use a single variable, and store both. It'll make

> > your
> > > WHERE clauses a lot simpler. If you need them separated for some

reason,
> > > create a query with computed fields DateValue([MyDateTimeField]) and
> > > TimeValue([MyDateTimeField])

> >
> >
> > I just personally find it easier to work with when date and time are in
> > different fields. I don't want to have to parse the values out whenever

I
> > need to reference them.
> >
> > God Bless,
> >
> > Mark
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
returning multiple values at the same time in a function Andy B. Microsoft VB .NET 16 11th Apr 2009 07:17 AM
Threading on Functions returning values A.K.Seerajdeen Microsoft Dot NET Framework 7 28th Jul 2007 08:01 AM
if functions returning different cell values to a question =?Utf-8?B?Y29uZnVzZWQgaW4gRkw=?= Microsoft Excel Worksheet Functions 4 25th Nov 2003 09:10 PM
Date() and Time() functions not returning values Mark A. Sam Microsoft Access Form Coding 4 13th Sep 2003 02:09 PM
Date() and Time() functions not returning values Mark A. Sam Microsoft Access Forms 4 13th Sep 2003 02:09 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:09 AM.