Hi Everybody,

I'm preparing a file with ODBC connections, to be used by other people.
I'm trying to change the parameters in "command text" (start date and end date), with a Macro (dependant on the value of a Cell in the worksheet).

I already have this code:

Sub Sales()
Dim UMES As String
UMES = Sheets("Sheet1").Range("D8").Value

With ActiveWorkbook.Connections(1).ODBCConnection
.CommandText = UMES
End With
End Sub
It is doing what I want... the problem is that in only works once.
The problem is that each time I run the Macro:
- it changes the connection name to something like "connection1", "connection2", "connection3" and so on.
- and keeps the previous connections names in the "connections list" (even if they are no longer used in the workbook)
- this means that the list of conenctions will increase each time I use the macro

So, the Macro will no longer point to the correct connection.

QUESTION: How to make it change the existing connection, instead of creating a new one?

I thank in advance for you input.