Solved

"Invalid Use Of Null" using CDate

Posted on 2004-10-08
8
904 Views
Last Modified: 2008-02-01
Hi All,

I have a date/time field in a table which is converted within a query from a string value via the following:

New Date Field: Int(CDate([Original Date Field]))

The problem is, I cannot view the query in design view if any records do not have data within the date field -- I get a "Invalid Use Of Null" error message.  This field will not always contain data, therefore, I need some way to work around this.

Suggestions?

Thanks,
Ed
0
Comment
Question by:MICHAED
8 Comments
 
LVL 51

Assisted Solution

by:Ryan Chong
Ryan Chong earned 50 total points
ID: 12261748
try:

New Date Field: IIF(IsDate([Original Date Field]) ,  Int(CDate([Original Date Field])) , 0)
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 50 total points
ID: 12261852
or

New Date Field: IIF(([Original Date Field])Is Null ,"",  Int(CDate([Original Date Field])))
0
 

Author Comment

by:MICHAED
ID: 12261857
Hi,

I'm getting "Invalid Operator" so I'm trying to find the expression's error....
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 11

Expert Comment

by:Jokra_the_Barbarian
ID: 12261869
Alternatively, you can avoid the IIF function by using:
     Format(Nz([Original Date Field], ""), "mm/dd/yy")
0
 

Author Comment

by:MICHAED
ID: 12261945
Jokra, will your function convert my date/time field ...or leave it as a string?
0
 

Author Comment

by:MICHAED
ID: 12261978
Folks, I've tried all suggestions -- and I do not get the error anymore.  However, the sort order is incorrect...it appears that the field is sorting like a string field rather than a date field.
0
 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 150 total points
ID: 12262000
Try:

New Date Field: IIf(IsNull([Original Date Field]),Null,Int(CDate([Original Date Field])))
0
 

Author Comment

by:MICHAED
ID: 12262032
Shane's version worked -- thanks all!

Ed
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question