Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dim varDate As Date ? 1

Status
Not open for further replies.

gusbrunston

Programmer
Feb 27, 2001
1,234
0
0
US
Good evening.

I tried to save a date and use the variable to populate a date field in another record:
Code:
     Public varDate As Date

then
Code:
     varDate = Me.txtTransDate
then
Code:
     Dim varDate As Date
     Me.txtTransDate = varDate

The result I got [3eyes] in Me.txtTransDate was something like [tt]"12/31/1899"[/tt].

Should have been [tt]"11/24/2003"[/tt]

How did I go wrong?

Thanks in advance,

[glasses][tt]Gus Brunston - Access2000(DAO)
Skill level based on 1-10: 7
Webmaster: www.rentdex.com[/tt]
 
Hi!

I'm thinking the locally declared varDate was used in stead of your global variable. The local variable has not been assigned a value - then the value is 0. Debug.Print Format(0,"mm/dd/yyyy") = 12/30/1899 in my version.

Suggest to remove the local date variable and use the public - and - if I might be so blunt, use a naming convention that reflects the scope of the variable, I tend to use use the following prefixes g for public (global) and m for module level publics.

HTH Roy-Vidar
 
Gus,

How is the text field that you are using defined?

Remember Access uses serial dates so if the text is converted on the fly you can get unexpected results.

Good luck.
 
Try something like this:

Public g_dDate As Date

then
g_dDate = format$(Me.txtTransDate, "short date")

then

Dim m_dDate As Date
m_dDate = g_dDate
Me.txtTransDate = m_dDate

 
[tt]
Thanks to all of you for your input.

I was trying to use a public variable for which I had not set a value. Because it was easier, I switched everything to module level variables and got the right date.

Roy, I appreciate the comment about designating global and module level variables in the prefix. I have been careful about form, query and control names, since I started, but I've named all variables with a "var" prefix. I'll be able to correct that with "Find and Replace" throughout the project, soon. Currently, I'm working on error handlers. Found an add-in that builds error handlers...tried it and it works great, looks like.

Again, thanks. I've learned more on Tek-Tips than anywhere else about Access and VBA.

Cheers,[tt]

[glasses][tt]Gus Brunston - Access2000(DAO)
Skill level based on 1-10: 7
Webmaster: www.rentdex.com[/tt]
 

Hi:

I wonder if I could check out one more thing in this thread?

I have now replaced all the public variables (previously named, e.g., "varOwnerID", with a "g" in front of the names, e.g., "gvarOwnerID".

I have declared all of these global variables in a module called "gbPubVars". I have several other global modules, such as "Utility Functions" which contains only the "IsLoaded" function which I got from the Northwind sample db.

My db is divided into a front end and back end. The back end is on one box in a peer-to-peer LAN, the front end, which is frequently revised, is on each box of the LAN.

Question: Should these public modules be on the front end or the back end?

They're now on the front end and work. (I really don't even know if they'd work if they were on the back end.) However, I'm interested in efficiency and procedure speed, and wonder if I should change where they're located.

Thanks for your comments.

Cheers,

[glasses][tt]Gus Brunston - Access2000(DAO)
Skill level based on 1-10: 7
Webmaster: www.rentdex.com[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top