Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to set a numeric field and date field as Null

Posted on 2004-04-22
20
Medium Priority
?
554 Views
Last Modified: 2008-03-10
Hi,
I have a problem

If I set a text field null like this:

Test = ""

How can I set a numeric field to null?  An empty string doesn't work because field types aren't compatible.

Thank You
0
Comment
Question by:LakshmanaRavula
  • 9
  • 7
  • 4
20 Comments
 

Expert Comment

by:ppaldus
ID: 10893175
I suggest you use vbNullString instead of double quotes"".
eg. set a text field to null use
Test = vbNullstring

To set a numeric or date field to null use the keyword Null.
Test=Null
0
 

Author Comment

by:LakshmanaRavula
ID: 10893202
when I use
Test = null

I get an error:  Invalid use of null.
0
 
LVL 54

Expert Comment

by:nico5038
ID: 10893362
Using:
test = null
Will only work when the tablefield it's connected to allows a zero length.
Just check the fielddefinition in the table.
To have the field just empty you can use the
test = ""

Looks strange, but Null means "not there" and "" means "empty" and they are different for a database !

Nic;o)
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

Expert Comment

by:ppaldus
ID: 10893382
Is test a field or variable? How/where are you setting Test to null?
0
 

Author Comment

by:LakshmanaRavula
ID: 10893503
Greetings Nico:

I'm using this in a function and when I use NULL to assign to a numeric field it is giving me an error

either Vbnullstring is also giving me an error


    If IsNull(BegDate) Then
        WorkDays = NULL
        Exit Function
        End If
   
0
 

Expert Comment

by:ppaldus
ID: 10893699
if WorkDays is a variable, it should be declared as a variant data type to accept a null value.
0
 
LVL 54

Expert Comment

by:nico5038
ID: 10893782
Make for a numeric field sure that the "Required" property is set to "No" to allow Null values in the table.

Nic;o)
0
 

Author Comment

by:LakshmanaRavula
ID: 10893791
Ihave written a function to calculate workdays and a append Query to insert the workdays in to a field.

Here is my total function


Public Function WorkDays(BegDate As Variant, EndDate As Variant) As Integer

    If IsNull(BegDate) Then
        WorkDays = Null
        Exit Function
        End If
    If IsNull(EndDate) Then
        WorkDays = Null
        Exit Function
        End If
    If BegDate > EndDate Then
        WorkDays = Null
        Exit Function
        End If
    If BegDate < #1/1/1980# Then
        WorkDays = Null
        Exit Function
        End If
    If BegDate = EndDate Then
        WorkDays = 0
        Exit Function
        End If

      Dim DateCnt As Variant
      DateCnt = BegDate
     
      Do While DateCnt < EndDate
         If Format(DateCnt, "ddd") <> "Sun" And Format(DateCnt, "ddd") <> "Sat" And _
            IsNull(DLookup("HoliDate", "Holidays", "[HoliDate]=#" & DateCnt & "#")) Then
         WorkDays = WorkDays + 1
         End If
         DateCnt = DateCnt + 1
      Loop
     
      If Format(EndDate, "ddd") = "Sun" Or Format(EndDate, "ddd") = "Sat" Or _
        Not IsNull(DLookup("HoliDate", "Holidays", "[HoliDate]=#" & EndDate & "#")) Then
        WorkDays = WorkDays - 1
        End If
       
   End Function

And this is my append Query

UPDATE TestNull SET TestNull.Field2 = WorkDays(BegDate, EndDate)
;


0
 

Author Comment

by:LakshmanaRavula
ID: 10893804
NICO-
The "Required" property is set to "No"
Error remains
0
 

Accepted Solution

by:
ppaldus earned 375 total points
ID: 10893854
You need to change the return data type to variant.

Public Function WorkDays(BegDate As Variant, EndDate As Variant) As Variant
0
 

Author Comment

by:LakshmanaRavula
ID: 10893917
Thanks Ppaldus
I changed it
But  it is giving me an compile error in query expression
0
 
LVL 54

Expert Comment

by:nico5038
ID: 10893934
Yep, thought you were referring to a form field, but for a function that's indeed the way to get a Null value returned.
But just why activate a function when the data isn't OK ?
And why have both Null and 0 workdays ?

Nic;o)
0
 
LVL 54

Expert Comment

by:nico5038
ID: 10893955
Make sure field2 has the required set to No

Nic;o)
0
 

Author Comment

by:LakshmanaRavula
ID: 10894059
I only set 0 where Begdate = Enddate

The data is Ok some times there won't be enddate
Then I need Null in workdays.

Later I have to process for the field2 like Where Field2 = Null

I ve already set Field2 required = NO
0
 
LVL 54

Expert Comment

by:nico5038
ID: 10894312
Looks to me you have the Workdays initially with a null value.
Just ignoring a Null begin and enddate in the queries WHERE clause will have the same effect as setting the Null workdays again to Null.

Nic;o)
0
 

Author Comment

by:LakshmanaRavula
ID: 10962790
I could not find out the exact problem some times it is giveing me error and some times it is working
0
 
LVL 54

Expert Comment

by:nico5038
ID: 10962898
Bit odd to see an answer follwed by "But  it is giving me an compile error in query expression"

Would have been better when you requested a moderator to delete/refund the question.

Nic;o)
0
 

Author Comment

by:LakshmanaRavula
ID: 10962938
I don't this option Nico
if I don't get asatisfactory answer can i ask the moderator to delete my question?
If so How to ask to delete a question

Thank you for the suggestion
0
 
LVL 54

Expert Comment

by:nico5038
ID: 10962984
Here's all there is to know:

http://www.experts-exchange.com/help.jsp#hs5

Nic;o)

0
 

Author Comment

by:LakshmanaRavula
ID: 10963048
Thank You
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

824 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