BradleyS
Active Member
- Joined
- Oct 28, 2006
- Messages
- 348
- Office Version
- 2010
- Platform
- Windows
I have the following code created in an Excel macro and I would like to change the date range to a rolling date i.e. from today in the last year.
WHERE (slotapp.slotdate>='20001006' And slotapp.slotdate<='20131006')
Therefore 20131006 needs to reference today() and 20001006 needs to be 1 year back from today.
Could somebody help me create this in the code?
Thank you
WHERE (slotapp.slotdate>='20001006' And slotapp.slotdate<='20131006')
Therefore 20131006 needs to reference today() and 20001006 needs to be 1 year back from today.
Could somebody help me create this in the code?
Thank you
Code:
Range("A1").Select
Application.CommandBars("Task Pane").Visible = True
With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DSN=Visual FoxPro Tables;UID=;;SourceDB=P:\WizAppt;SourceType=DBF;Exclusive=No;BackgroundFetch=Yes;Collate=Machine;Null=Yes;Deleted=Yes" _
), Array(";")), Destination:=Range("A1"))
.CommandText = Array( _
"SELECT slotapp.slotdate, slotapp.staff_id, slotapp.type, slotapp.session_id, slotapp.count, slotapp.time, slotapp.pat_id, slotapp.pat_label, slotapp.arrived, slotapp.in, slotapp.out, slotapp.expdur, s" _
, _
"lotapp.actdur, slotapp.comment, slotapp.date_made, slotapp.time_made, slotapp.who_made, slotapp.method" & Chr(13) & "" & Chr(10) & "FROM slotapp slotapp" & Chr(13) & "" & Chr(10) & "WHERE (slotapp.slotdate>='20001006' And slotapp.slotdate<='20131006') AND " _
, "(slotapp.count=$1)" & Chr(13) & "" & Chr(10) & "ORDER BY slotapp.slotdate")
.Name = "Query from Visual FoxPro Tables"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With