So I have inherited a workbook that contains a broken macro that I can't figure out how to fix and I'm hoping the forums can come through for me and help me out of a bind...again![]()
Here is the code in the macro :
Sub RefreshQuery()
'
' RefreshQuery Macro
'
Dim queryPreText As String
Dim queryPostText As String
Dim valueToFilter As String
Dim paramPosition As Integer
valueToFilter = "[GL_Posting_Date] <="
With ActiveWorkbook.Connections("XXXX dbo view_AR_Apply_Detail").OLEDBConnection
queryPreText = .CommandText
paramPosition = InStr(queryPreText, valueToFilter) + Len(valueToFilter) - 1
queryPreText = Left(queryPreText, paramPosition)
queryPostText = .CommandText
queryPostText = Right(queryPostText, Len(queryPostText) - paramPosition)
queryPostText = Right(queryPostText, Len(queryPostText) - InStr(queryPostText, ")") + 1)
.CommandText = queryPreText & " '" & Range("N3").Value & "'" & queryPostText
End With
ActiveWorkbook.Connections("XXXX dbo view_AR_Apply_Detail").Refresh
With ActiveWorkbook.Connections("PGLMD dbo view_AR_Apply_Detail").OLEDBConnection
queryPreText = .CommandText
paramPosition = InStr(queryPreText, valueToFilter) + Len(valueToFilter) - 1
queryPreText = Left(queryPreText, paramPosition)
queryPostText = .CommandText
queryPostText = Right(queryPostText, Len(queryPostText) - paramPosition)
queryPostText = Right(queryPostText, Len(queryPostText) - InStr(queryPostText, ")") + 1)
.CommandText = queryPreText & " '" & Range("N3").Value & "'" & queryPostText
End With
ActiveWorkbook.Connections("YY dbo view_AR_Apply_Detail").Refresh
With ActiveWorkbook.Connections("YY dbo view_AR_Apply_Detail").OLEDBConnection
queryPreText = .CommandText
paramPosition = InStr(queryPreText, valueToFilter) + Len(valueToFilter) - 1
queryPreText = Left(queryPreText, paramPosition)
queryPostText = .CommandText
queryPostText = Right(queryPostText, Len(queryPostText) - paramPosition)
queryPostText = Right(queryPostText, Len(queryPostText) - InStr(queryPostText, ")") + 1)
.CommandText = queryPreText & " '" & Range("N3").Value & "'" & queryPostText
End With
ActiveWorkbook.Connections("YY dbo view_AR_Apply_Detail").Refresh
End Sub
-----
N2 is the first date and N3 is the last date that I am looking for information for. I can't get it to run between them. Any idea how to fix the macro? The person before me got it this far but couldn't make it work right.
Any help is much appreciated.
Thanks again
Bookmarks