livetolearn4life
New Member
- Joined
- Jul 14, 2020
- Messages
- 15
- Office Version
- 2019
- 2016
- 2013
- Platform
- Windows
Hello hope you all are having a great day!
i'm looking for a solution to a " Run-time error '1004': SQL Syntax Error" that occurs at the " .Refresh BackgroundQuery:=False" line. Any help would be greatly appreciated. Thanks!
Sub Purged_MO_HRS()
''QUERY HOURS DATA FOR FAI AND TLG MANUFACTURING ORDERS THAT HAVE PURGED/CLOSED OUT
Worksheets("Purged MO HRS").Activate
Cells.Select
Selection.ListObject.QueryTable.Delete
Selection.ClearContents
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"ODBC;DSN=AMFLIB1;UID=ddt;PWD=xs892kmfg", Destination _
:=Range("$A$1")).QueryTable
.CommandText = Array( _
"SELECT MOHMST.ORDNO, MOHMST.REFNO, MOHMST.JOBNO, MOHMST.FITEM, MOHMST.FDESC, MOHRTG.OPSEQ, MOHRTG.WKCTR, MOHRTG.SRLHU, MOHRTG.SSLHU, MOHRTG.SETCS, MOHRTG.OPSTC, MOHRTG.QUETM, MOHRTG.RLHTP, MOHRTG.RLHTD, " _
, "" & Chr(13) & "" & Chr(10) & "FROM S1099F6P.AMFLIB1.MOHMST MOHMST, S1099F6P.AMFLIB1.MOHRTG MOHRTG" & Chr(13) & "" & Chr(10) & "WHERE MOHRTG.CLDT = MOHMST.CLDT AND MOHRTG.ORDNO = MOHMST.ORDNO AND ((MOHMST.CRUS='EFS') " _
, "AND (MOHMST.OSTAT<'99') OR (MOHMST.CRUS='KKR') AND (MOHMST.OSTAT<'99') OR (MOHMST.CRUS='CBL') AND (MOHMST.OSTAT<'99') OR (MOHMST.CRUS='TBD') AND (MOHMST.OSTAT<'99') AND " _
, "(MOHMST.JOBNO Like '%240124') OR (MOHMST.CRUS='FTE') AND (MOHMST.OSTAT<'99') AND (MOHMST.JOBNO Like '%240124') OR (MOHMST.CRUS='DSN') AND (MOHMST.OSTAT<'99') AND (MOHMST.JOBNO Like '%240124')) " _
)
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "Table_Purged_MO_HRS"
.Refresh BackgroundQuery:=False
End With
Range("A1").Select
ActiveSheet.ListObjects("Table_Purged_MO_HRS").TableStyle = _
"TableStyleLight13"
End Sub
i'm looking for a solution to a " Run-time error '1004': SQL Syntax Error" that occurs at the " .Refresh BackgroundQuery:=False" line. Any help would be greatly appreciated. Thanks!
Sub Purged_MO_HRS()
''QUERY HOURS DATA FOR FAI AND TLG MANUFACTURING ORDERS THAT HAVE PURGED/CLOSED OUT
Worksheets("Purged MO HRS").Activate
Cells.Select
Selection.ListObject.QueryTable.Delete
Selection.ClearContents
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"ODBC;DSN=AMFLIB1;UID=ddt;PWD=xs892kmfg", Destination _
:=Range("$A$1")).QueryTable
.CommandText = Array( _
"SELECT MOHMST.ORDNO, MOHMST.REFNO, MOHMST.JOBNO, MOHMST.FITEM, MOHMST.FDESC, MOHRTG.OPSEQ, MOHRTG.WKCTR, MOHRTG.SRLHU, MOHRTG.SSLHU, MOHRTG.SETCS, MOHRTG.OPSTC, MOHRTG.QUETM, MOHRTG.RLHTP, MOHRTG.RLHTD, " _
, "" & Chr(13) & "" & Chr(10) & "FROM S1099F6P.AMFLIB1.MOHMST MOHMST, S1099F6P.AMFLIB1.MOHRTG MOHRTG" & Chr(13) & "" & Chr(10) & "WHERE MOHRTG.CLDT = MOHMST.CLDT AND MOHRTG.ORDNO = MOHMST.ORDNO AND ((MOHMST.CRUS='EFS') " _
, "AND (MOHMST.OSTAT<'99') OR (MOHMST.CRUS='KKR') AND (MOHMST.OSTAT<'99') OR (MOHMST.CRUS='CBL') AND (MOHMST.OSTAT<'99') OR (MOHMST.CRUS='TBD') AND (MOHMST.OSTAT<'99') AND " _
, "(MOHMST.JOBNO Like '%240124') OR (MOHMST.CRUS='FTE') AND (MOHMST.OSTAT<'99') AND (MOHMST.JOBNO Like '%240124') OR (MOHMST.CRUS='DSN') AND (MOHMST.OSTAT<'99') AND (MOHMST.JOBNO Like '%240124')) " _
)
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "Table_Purged_MO_HRS"
.Refresh BackgroundQuery:=False
End With
Range("A1").Select
ActiveSheet.ListObjects("Table_Purged_MO_HRS").TableStyle = _
"TableStyleLight13"
End Sub