473,396 Members | 2,017 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Clearing out Date Variables

I have a form where users input some dates, these dates are then written to date variables.

I need to clear out the date variables with either an empty string or a null value. Currently, I am using 12:00 AM to clear out the date value, however this is now causing confusion.

Can anyone tell me out to clear out the variable so it is empty.

Thanks so much

Pam
Feb 19 '07 #1
7 3416
ADezii
8,834 Expert 8TB
I have a form where users input some dates, these dates are then written to date variables.

I need to clear out the date variables with either an empty string or a null value. Currently, I am using 12:00 AM to clear out the date value, however this is now causing confusion.

Can anyone tell me out to clear out the variable so it is empty.

Thanks so much

Pam
What you can't do:
__1 You cannot set a Date Variable to an Empty String since this is reserved for Strings.
__2 You cannot set a Date Variable to Null since only Variant Data Types can be set to a Null Value.
__3 You cannot set a Date Variable to 0 since that would return 12:00 A.M.
__4 You cannot set a Date Variable = Nothing because that is reserved for Object Variables.
__5 If these Date Variables are declared in a Form Module then once you close the Form they will automatically go out of Scope and lose their value. If they are declared as Public in a Standard Module, they will retain their value for the lifetime of the application which could be a problem.
__6 You can convert the Variable to a Variant then assign it to vbNull as in below, but then it simply returns 12/31/1899.
Expand|Select|Wrap|Line Numbers
  1. MyDate = CVar(MyDate)
  2. MyDate = vbNull
  3. Debug.Print MyDate ==> 12/31/1899
__7 In short, I'm kind of stumped. I'm sure some of the other Experts/Moderators will shed some light on your dilemma and meanwhile I'll still be working on it. Please be patient.
Feb 19 '07 #2
Thank you for your response.

To shed a little more light, they are stored at public variables which is why I need to clear the values.
Feb 19 '07 #3
ADezii
8,834 Expert 8TB
Thank you for your response.

To shed a little more light, they are stored at public variables which is why I need to clear the values.
The closet solution that I can come up with is to Declare the Date Variables As Variants as opposed to Date/Time, and then set them to vbNull. The will then contain a value of, believe it or not, 1.
Expand|Select|Wrap|Line Numbers
  1. Dim MyDate As Variant
  2. MyDate = #1/1/2007#
  3.  
  4. Debug.Print MyDate      'output: 1/1/2007
  5.  
  6. MyDate = vbNull
  7. Debug.Print MyDate      'output: 1
Feb 19 '07 #4
NeoPa
32,556 Expert Mod 16PB
...Or you could set a Variant variable as Null.
This cannot be done in a typed variable as ADezii says, but Variants are special cases for that and can be set to Null.
Testing for Null values in code can be done with the IsNull() function.
Feb 20 '07 #5
ADezii
8,834 Expert 8TB
I have a form where users input some dates, these dates are then written to date variables.

I need to clear out the date variables with either an empty string or a null value. Currently, I am using 12:00 AM to clear out the date value, however this is now causing confusion.

Can anyone tell me out to clear out the variable so it is empty.

Thanks so much

Pam
I think we have finally arrived at your solution although it didn't work a couple of hours ago. Please don't ask me why.
Expand|Select|Wrap|Line Numbers
  1. Dim MyDate As Variant
  2. MyDate = #1/1/2007#
  3.  
  4. Debug.Print MyDate      'output: 1/1/2007
  5.  
  6. MyDate = Null
  7. Debug.Print MyDate      'output: Null
Feb 20 '07 #6
Thanks everyone.

I will change them to variants. I truly appreciate your advise.
Feb 20 '07 #7
NeoPa
32,556 Expert Mod 16PB
Not a problem Pam.
Glad you got what you were after :)
Feb 20 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Andrew Poulos | last post by:
If I'm using DOM methods to dynamically create elements in a page is it necessary for me to clear whatever variables I used to create the elements when the page unloads? I'm reading bits and...
1
by: hortoristic | last post by:
We are using JavaScript to Enable/Disable certain fields on web pages based on business rules. A simple example is if when using an option type tag, and the two options are Yes and No. If YES...
12
by: Hans B | last post by:
Please bear with me if I ask silly questions....I am a somewhat newbie to the C language.... If I had: struct test1_{ unsigned char mycount1; unsigned short mycount2; unsigned short...
1
by: raghavendra | last post by:
Hi, i am facing problem clearing screen in console application. As, in C++ we have clrscr(); Is? their any similar type of function is avaliable.. Raghavendra...
0
by: PD | last post by:
I am trying to stream out a PDF file via the response object and when I execute the code it always brings up the first document that I pulled up.Even when I step through the code, I can see the new...
4
by: Amy | last post by:
I'm having a problem with clearing my session variables. I'm using session variables to pass data from a web form to a pdf generator. The problem comes in when a user goes back to the original...
12
by: Rob Meade | last post by:
Hi all, Ok - I've come from a 1.1 background - and previously I've never had any problem with doing this: Response.Write (Session("MyDate").ToString("dd/MM/yyyy")) So, I might get this for...
1
by: Pam Poulos | last post by:
I have a form where users input some dates, these dates are then written to date variables. I need to clear out the date variables with either an empty string or a null value. Currently, I am...
6
by: =?Utf-8?B?R2Vv?= | last post by:
Hi, I use lots of sessions. I want to clear the unwanted sessions when I leave a page. I cant use ViewState as it will slow down the pages. Could some one help me on this?
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.