Days Until Christmas

Lister

Z Shift
Local time
Today, 16:05
Joined
Aug 24, 2003
Messages
305
As as I have said befor, my VB an't that hot. (Some would say tepid)
But I am working on it.

I thought just for fun to add a button to the swicthboard of our database with a little .BMP on it of Santa and when clicked it would say...

"Only " ### " Days Until Xmas, So Be Afraid"

I wrote my code in the Debug window..

Dim dtmDateNow As Date
Dim dtmXmas As Date
dtmDateNow = Date
dtmXmas = DateSerial(Year(Date), 12, 25)
? DateDiff("d", dtmDateNow, dtmXmas)
113

Looked fine, so attached it to a button.


Private Sub Command15_Click()
DaysToXmas
End Sub

Public Function DaysToXmas()

Dim dtmDateNow As Date
Dim dtmXmas As Date
dtmDateNow = Date
dtmXmas = DateSerial(Year(Date), 12, 25)

MsgBox "Only " & DateDiff("d", dtmDateNow, dtmXmas) & " Until Xmas, So Be Afraid"

End Function

But on clicking the button in form view, I get 157 days instead of 113.
Now I know this is simple VB but I can't see what I am doing wrong.
Is it because I am in NZ with Xmas as #25/12/03# and access see it in US as #12/25/03# ?
Just can't understand why it would work in the debug window and not on the form.
Any help would be great, thanks.
 
Lister,

This works, yours should to. It's not really a function as it
does not return a value.

Code:
Public Function DaysToXmas()
   MsgBox "Only " & DateDiff("d", Date, DateSerial(Year(Date), 12, 25)) & " Until Xmas, So Be Afraid"
End Function

Wayne
 
Yip, she fly’s

Bit on the spaghetti side mine by comparison.

Thanks for that.

:)
 
From the debug window:

? date()
9/3/03
dteMyDate = date()
? DateDiff("d",dteMyDate,DateSerial(Year(dteMyDate),12,25))
113
 
What doesnt work in the UK ?

Also

MsgBox "Only " & DateSerial(Year(Date), 12, 25) - Date & " Until Xmas, So Be Afraid"

Will work (faster)....

Regards
 
Thanks, Lister and Wayne. I've borrowed it to put complete fear into the office. I wonder what title you have given the message box, Lister? Cheers
 
Rich-
Don't understand why that wouldn't work in the UK. Granted, with different regional settings ? date() would result in output in a different format, but the rest of the equation is region-neutral. Please fill us in.
Bob
 
Manilaman, you missed "DAYS Untill etc:D
Bob when I tried the formula this morning Access told me I'd missed Christmas by 5 days, now it's correct:confused:
 
Just the standard heading.
But here’s the .bmp to make your button more festive.

:D
 

Attachments

Hi Lister

Kia ora koe, e hoa.

No fern, no rugby ball! Oh, dear. But, seriously, thanks very much. Cheers
 
No one give me a gun

Busted
I have just been chewed out by the sale manager because he didn’t fine the “Santa Button” on the switchboard at all funny.
He then wanted to know how long it took to make, what it was for and what it was meant to mean.
The Brain Dead User [BDU] then went on to ask me what else I was working on that was a complete waste of time.
As if he would know, he can’t ever work out how to use the filter/sort buttons.
I was actually working on a MsgBox that would run when work was behind its delivery dates or finished dates.
I was using #25/12/2003# as a constant to start with and have now started to try to get it to work with variables from the delivery date them selves.
The Santa Button has been in for two days now, and everyone has seen it, and laughed, except BDU. In fact it’s started a running gag of “So how many days till Xmas is it?”
So what dose he do? He spams an e-mail to all departments asking who did it, and how it was a waste of “His” money and time. Knowing full well that it was me. No one has access to the database construct except me.
And then he came down and through all his toys out of the playpen.
I sometimes wonder why I bother.
I would love to get on his PC and change his spell auto change to Peter = W**ker, and see what he thinks of that.
God, some people need to grow as sense of humour or what.

Ok I have finished ranting, I will stop now.
 
Sadly, doesn't matter which side of the globe, people like that are in charge. You have to try to adapt to them, unfortunately. I came over here thinking all that sort of small town thing would be ended. But it's very little different. And in many areas far worse.

At least, coding and manipulating databases can be really interesting and involving. I imagine having sales as his sole preoccupation must be thoroughly boring. Perhaps you should feel sympathy. And access to the www is a plus for you. Have you looked at Martin Green's site on www.fontstuff.com? He's an amazing programmer and there are excellent ideas there.

Visual.net is about to be installed onto this machine. The prospect brightens my world. Perhaps you should propose something like that to your charming User. By the by, what price for a beer over there now? Cheers, keep coding, keep smiling!
 
Every db needs to have a little bit of fun added to it just for the sake of sanity. If you are using some type of user security then you could have the santa button not visible for the BDU.

HO HO HO
 

Users who are viewing this thread

Back
Top Bottom