Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
| Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old May 18th, 2006, 01:02 PM
Authorized User
 
Join Date: Dec 2005
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Easy Question: Setting a variable to null

Ok, so I've searched the internet and help files and I still haven't found an answer. Is there any way in VBA to set a variable back to null once it has been assigned a value?
Thanks for your help
-Enoch

Enoch
__________________
Enoch
  #2 (permalink)  
Old May 18th, 2006, 01:04 PM
Friend of Wrox
 
Join Date: Oct 2004
Location: Clinton, UT, USA.
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

What kind of variable is it?

Mike
EchoVue.com
  #3 (permalink)  
Old May 18th, 2006, 02:00 PM
Authorized User
 
Join Date: Dec 2005
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

An integer, the truth is I avoided the problem by just initializing it to a negative number and then treating -1 as null, because I really didn't need any of the differences null offers. But I was wondering for future reference.
Thanks
-Enoch

Enoch
  #4 (permalink)  
Old May 18th, 2006, 02:07 PM
Friend of Wrox
 
Join Date: Oct 2004
Location: Clinton, UT, USA.
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

That Works! Actually I don't think that you can set an integer to null. When it is initialized, I think it is assigned a default value of 0, but that is as close as it ever gets to null.



Mike
EchoVue.com
  #5 (permalink)  
Old May 19th, 2006, 08:52 AM
Authorized User
 
Join Date: Dec 2005
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks once again for your help

Enoch
  #6 (permalink)  
Old May 19th, 2006, 09:18 AM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

As long as the table does not require a value to be input for the record, you should be able to set the integer to null (even if the default is zero) simply by doing something like this for the textbox that is bound to the field.

Me.txtInteger = Null

I assume you can do this because what if there truly is no value for that record? A zero is misleading because you think that the actual value is zero when the value is really "nothing was ever entered."


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
  #7 (permalink)  
Old May 19th, 2006, 12:37 PM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

That last one would do it for the field value.

As far as setting an integer variable to Null, it can't be done. Integers are initialized as 0. Null means no value, so that Null can never equal Null, but 0 = 0. So Null has a different meaning.

Once you declare the variable as an integer, Null is not available to you.


mmcdonal
  #8 (permalink)  
Old May 22nd, 2006, 09:35 AM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Actually, if you do not specify a default field value when you create a table and you do not specify a default field value in the form based on the table, then an integer field is NOT initialized to zero. It's null.

An integer VARIABLE created in VBA may be initialized to zero automatically upon runtime of the VBA code, but not a field in the table.

I just tested it. I created a table, added an integer field, took away the default value setting, and left it blank. When I started entering data, the default integer value was null.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
  #9 (permalink)  
Old May 22nd, 2006, 10:30 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: Clinton, UT, USA.
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Thanks Greg,

I stand corrected, but more informed - I think my dabblings in java a few years back are coming back to haunt me :)

Mike

Mike
EchoVue.com


Similar Threads
Thread Thread Starter Forum Replies Last Post
hopefully an easy question davehodges Access 1 November 7th, 2007 06:36 AM
Easy Question hexOffender Beginning PHP 2 July 12th, 2006 05:03 AM
Easy Question yikomaka Visual C++ 0 June 13th, 2005 08:50 PM
Easy Question - I think gmoney060 Classic ASP Basics 3 November 2nd, 2004 06:54 PM
easy question khautinh C# 4 August 6th, 2003 01:17 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.