Lister
Z Shift
- Local time
- Today, 19:56
- 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.
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.