VBA Date returns 1/1/1900 in one project only

duggie33

Board Regular
Joined
Nov 19, 2018
Messages
83
Office Version
  1. 365
Platform
  1. Windows
Sorry if this has been asked before, searching for it multiple ways returns all kind of unrelated results.

I have one VBA project that consistently returns 1/1/1900 for "Date". I could have two projects open, with Project A in focus, type ?date in the Immediate window and get a return of 8/10/2021, with Project B (for bad) in focus, type ?date and it returns 2 (1/1/1900). Is there a project specific setting, a reference, or something else that would cause this?

Background: using date picker by Trevor Eyre and would like the it to open and display this month (August 2021) rather than January 1900. It uses today's date to set the month showing on open.
bad date.jpg
good date.jpg

Thanks,

Doug
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

duggie33

Board Regular
Joined
Nov 19, 2018
Messages
83
Office Version
  1. 365
Platform
  1. Windows
After copying over sheets, forms, and modules to a new file I have isolated when the "Date" issue arises. It works fine until I add one specific form. Without the form ?Date returns 8/11/2021. With the form imported, ?Date returns " 2 " like shown in original post.

Is there a form property that would cause this to happen? I have stared at them for a while and none seem like they would affect the Date function. Could the form be corrupt somehow causing this? Any ideas are welcome.

Thanks,

Doug
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
37,828
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Is the form actually loaded when this happens?
 

duggie33

Board Regular
Joined
Nov 19, 2018
Messages
83
Office Version
  1. 365
Platform
  1. Windows
No, while viewing the form (edit mode, View Object) and type ?Date in the Immediate window. If I remove the form from the project the ?Date shows correctly.

After a little more experimenting, I discovered that adding a blank form (not that specific form like I thought) I get the same problem. So I thought it might be an issue with having four forms. Tried a new file with four forms, works fine so it has to be something in this file.
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
37,828
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS

ADVERTISEMENT

Hard to say without the file. The only thing I can think of would be some code that is actually altering the date, since you can't use date as the name of anything in your own code.
 
Solution

duggie33

Board Regular
Joined
Nov 19, 2018
Messages
83
Office Version
  1. 365
Platform
  1. Windows
I knew that and must have blanked when I created a Public Enum with "Date" as a member. I kept at deleting things one at a time to see if the issue went away after deleting Modules and that is when the issue disappeared. I knew immeditately that I did that...doh.

Thanks for taking the time to question it Rory!

As an aside, why doesn't Compiling recognize my mistake, using a reserved word? Why does it only cause an issue after having four forms in the project? Don't spend much time on these questions, my issue has been resolved. Thanks again.

Doug
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
37,828
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
I don't know - the compiler should complain, but has always been a bit weak on Enums in my opinion. I have no clue why adding the last form made any difference though.
 

Forum statistics

Threads
1,148,327
Messages
5,746,128
Members
423,994
Latest member
blzxatly

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top