|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Date problem in Access query
Hi,
Am running the code below, however for some reason it's not selecting the correct records from access, ie. it's messing up the dates... What am I doing wrong? Thanks! Dim Ddate as Date DDate = "11/08/2006" Dim nb1W as Date Dim nb1M as Date nb1W = DDate + 7 nb1M = DDate + 31 Dim strSelect1W as String Dim strSelect1M as String strSelect1W = "Select * into Z from X where Y < #" & nb1W & "#;" strSelect1M = "Select * into Z from X where Y > #" & nb1W & "# and Y <= #" & nb1M & "#;" DoCmd.RunSQL strSelect1W DoCmd.RunSQL strSelect1M |
|
#2
|
||||
|
||||
|
Hi,
I think your problem is caused by the fact that you cant just add a number to a date in the same way as you would an integer. You need to use the dateadd function. Code:
Dim Ddate as Date
DDate = "11/08/2006"
Dim nb1W as Date
Dim nb1M as Date
nb1W = DateAdd("d", 7, DDate)
nb1M = DateAdd("M", 1, DDate)
Do a Google search for the DateAdd Function for a full explanation. Also, DateDiff may be of use to you if you ever need to compare two dates!!! |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Date problem in Access query |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|