View Full Version : Relinking Queries through Code


Meltdown
12-15-2008, 02:46 AM
Hi all,

I have a lot of pass-through queries in a database, the connection string is stored in the properties of the query, does anyone have any code to relink these queries when the database opens?

I think querydefs might do it but I haven't come accross any examples so far.

Thanks
Melt

Meltdown
12-15-2008, 03:33 AM
OK I got this coded myself, not to difficult after all.

Dim qdf As dao.QueryDef
Dim dbs As dao.Database

Set dbs = CurrentDb

' create connection string
Dim strConnect As String
strConnect = "ODBC;DRIVER={SQL Native Client}" _
& ";SERVER=server_name" _
& ";DATABASE=database_name" _
& ";UID=my_user" _
& ";Trusted_Connection=Yes" & ";"

For Each qdf In dbs.QueryDefs

If qdf.Type = dbQSQLPassThrough Then
qdf.Connect = strConnect
End If

Next qdf

dbs.Close