473,325 Members | 2,805 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,325 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 3414
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.