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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

QUERY TO APPEND DATES

Status
Not open for further replies.

Jean9

Programmer
Dec 6, 2004
128
US
I would like to write an append query that would append the weekdays to a temp table for every weekday for a year prior to today's date and every weekday for a year from today's date. How would I write that?
Thanks for your help,
J9
 
Don't know of any temp tables in Access but could be mistaken; if not maybe try the SQL Server forum???

Silence is golden.
Duct tape is silver.
 
If 'temp' was a generic term, here's a way to put weekday dates into a table...

Private Sub AppDates()

Dim intCtr As Integer
Dim datWork As Date
datWork = Now()
For intCtr = 0 To 365
Select Case Weekday(datWork)
Case 2 To 6
CurrentProject.Connection.Execute "insert into
DATE_TABLE VALUES (#" & datWork & "#)"
End Select
datWork = DateAdd("d", -1, datWork)
Next

datWork = Now()
datWork = DateAdd("d", 1, datWork) 'tomorrow
For intCtr = 0 To 365 Step 1
Select Case Weekday(datWork)
Case 2 To 6
CurrentProject.Connection.Execute "insert into
DATE_TABLE VALUES (#" & datWork & "#)"
End Select
datWork = DateAdd("d", 1, datWork)
Next

End Sub


"Adam was not alone in the Garden of Eden, however,...much is due to Eve, the first woman, and Satan, the first consultant." Mark Twain
 
One loop, leap years consindered also.

Code:
Sub ADD2YearsDates()

Dim iCounter As Integer
Dim iStart As Integer
Dim iStop As Integer
Dim RunningDate As Date
iStart= DateDiff(DateAdd("y", -1, Date()), Date())
iStop= DateDiff(Date(), DateAdd("y", 1, Date())

For iCounter = iStart  To iStop 
  RunningDate= Date() + iCounter
  Select Case Weekday(RunningDate)
    Case 2 To 6
       CurrentProject.Connection.Execute "ISNERT INTO
yourDatesTable(myDate) VALUES (#" & RunningDate & "#)"
  End Select
Next

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top