Thanks for the redirection!! I didnt pick it up cos of the title!
If I input the date 01/22/04
I get the error message:
[Microsoft] [ODBC SQL Server Driver] [SQL Server]Line 3: Incorrect syntax near ‘2004-01-22 00:00:00’.
I have no idea what I am doin wrong!!!!!
Any Ideas?
Sub GenerateForm()
Dim dat As Date, result As Boolean
Dim cutdate As String, n As Long
With EnterDate
.dat1 = DateSerial(Year(Now), Month(Now), Day(Now))
.InsrtDate = CStr(.dat1)
.SpinButton1 = 0
.Label1 = "Please select the date from which you wish to get the data"
.Show
If .result = False Then Exit Sub
Application.ScreenUpdating = False
End With
finaldat = EnterDate.InsrtDate
finaldat = Format(CStr(finaldat), "yyyy-mm-dd hh:00:00")
If EnterDate.result = True Then
ActiveWorkbook.Worksheets.Add
With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DSN=ServiceCenterPROD;Description=Service Center Production Database;UID=svcprod;PWD=*******;APP=Microsoft Office XP;WSID=AC6S" _
), Array("2BKN9ZW1B8")), Destination:=Range("A1"))
.CommandText = Array( _
"SELECT probsummarym1.number, probsummarym1.open_time, probsummarym1.close_time, probsummarym1.resolution, probsummarym1.brief_description, probsummarym1.resolved_by, probsummarym1.resolved_time, probs" _
, _
"ummarym1.acc_subservice, probsummarym1.acc_outage_start, probsummarym1.acc_outage_end, probsummarym1.company, probsummarym1.severity_code" & Chr(13) & "" & Chr(10) & "FROM ServiceCenter.dbo.probsummarym1 probsummarym1" & Chr(13) & "" & Chr(10) & "WHERE (pr" _
, _
"obsummarym1.open_time>=ts '" & finaldat & "') AND (probsummarym1.resolution Like '%NETWORKS%') AND (probsummarym1.severity_code='1')" & Chr(13) & "" & Chr(10) & "ORDER BY probsummarym1.close_time" _
)
.Name = "Query from ServiceCenterPROD"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=True
End With
End If
If I input the date 01/22/04
I get the error message:
[Microsoft] [ODBC SQL Server Driver] [SQL Server]Line 3: Incorrect syntax near ‘2004-01-22 00:00:00’.