Hello, all. I have the following code in Access that allows me to bring in some pass-through data and, while it works, it is a pain to list out my SQL code (see strSQL) at great length with quotes and line continues when I think I should be able to just refer to the saved pass-through query (PassThroughAgents) that I am copying out the SQL from in the first place. I apologize as I am sure there is a simple answer to all this, but I can't seem to make this work without having the SQL code listed.
Also, if it has any bearing, I need this to be part of an automated process- so no specifying data connection parameters or the like at runtime.
Thanks in advance!
Code:
Public Sub AgentsPassThrough()
On Error GoTo Error_Handler
Dim qdfPassThrough As DAO.QueryDef, MyDB As Database
Dim strConnect, strSQL As String
DoCmd.SetWarnings False 'Turn off confirmation prompt to user
If Not IsNull(CurrentDb.QueryDefs("PassThroughAgents").SQL) Then 'doesn't exist
CurrentDb.QueryDefs.Delete "PassThroughAgents"
End If
Set MyDB = CurrentDb()
strSQL = Same SQL that is in "PassThroughAgents"
Set qdfPassThrough = MyDB.CreateQueryDef("PassThroughAgents")
strConnect = "blah;"
qdfPassThrough.Connect = "ODBC;" & strConnect
qdfPassThrough.SQL = strSQL
qdfPassThrough.ReturnsRecords = True
qdfPassThrough.Close
Application.RefreshDatabaseWindow
DoCmd.OpenQuery "PassThroughAgents", acViewNormal, acReadOnly
DoCmd.Maximize
DoCmd.RunSQL ("DELETE DEF_AGENT_TO_SITE_MAPPING.* FROM DEF_AGENT_TO_SITE_MAPPING;")
DoCmd.RunSQL ("INSERT INTO DEF_AGENT_TO_SITE_MAPPING SELECT * FROM PassThroughAgents;")
DoCmd.Close acQuery, "PassThroughAgents"
DoCmd.SetWarnings True 'Turn back on confirmation prompt to user
If Err.Number = 0 Then Exit Sub
Error_Handler:
DisplayError Err.Number, Err.Description
Exit Sub
End Sub