Here is the code.
Public Sub subQueryReplace()
'=============================================
Dim strSQLIn As String
Dim strSQLOut As String
Dim db As DATABASE
Dim qd As QueryDef
Dim rs As Recordset
Set db = CurrentDb
'====================================================
'This is a list of all your query's you want to update
'======================================================
Set rs = db.OpenRecordset("SELECT distinct Name FROM MSysObjects WHERE MSysObjects.Type=5 and name in('qryTEST')", dbOpenSnapshot)
With rs
Do While Not rs.EOF
strSQLIn = db.QueryDefs(!NAME).sql
'==============================================
'Replace "Old table name" & "new table name"
'==============================================
strSQLOut = fncReplace(strSQLIn, "Old table name", "new table name"
'==========================================
'Rename old qry or you can delete - what ever blows your hair back
'docmd.DeleteObject acQuery,rs!NAME
'==========================================
DoCmd.Rename "OLD_" & rs!NAME, acQuery, rs!NAME
'==========================================
'Make your new qry
'==========================================
Set qd = db.CreateQueryDef(!NAME, strSQLOut)
'==========================================
'Move next
'==========================================
rs.MoveNext
Loop
End With
End Sub
Public Function fncReplace(ByVal strSentence As String, varField As Variant, varValue As Variant) As String
Dim strOut As String
Dim lngPos As Long
Dim lngLenValue As Long
lngLenValue = Len(varValue)
lngPos = InStr(1, strSentence, varField)
strOut = strSentence
Do While lngPos > 0
strOut = Left(strOut, lngPos - 1) & varValue
strOut = strOut & Mid(strSentence, lngPos + Len(varField), Len(strSentence) - lngPos + Len(varField))
strSentence = strOut
If lngLenValue > 1 Then
lngPos = InStr(lngPos + lngLenValue, strOut, varField)
Else
lngPos = InStr(lngPos, strOut, varField)
End If
Loop
If Len(strOut) = 0 Then
fncReplace = strSentence
Else
fncReplace = strOut
End If
End Function