Solved

ODBC Connect Str

Posted on 2002-03-07
3
421 Views
Last Modified: 2012-06-27
I am running an Access to SQL server application.
When setting up the Connect String for pass through queries I am pointing it to the live DB called AdaptData   ie;ODBC;DRIVER=SQL Server;SERVER=DIMENSIONS;UID=scott;PWD=password;DATABASE=AdaptData

I also have a test DB set up called BackUp

Due to me having to change the connect string between Databases so I can test code I am currently having to change the Connect String on Each Pass Through, and there are a few!!

Is there a way I can place a variable in this connect string and change it through code..

ie; ODBC;DRIVER=SQL Server;SERVER=DIMENSIONS;UID=scott;PWD=password;DATABASE=[Variable]

Possible???

Cheers

Scott
0
Comment
Question by:scottsanpedro
3 Comments
 
LVL 5

Accepted Solution

by:
TheMek earned 100 total points
Comment Utility
Hi Scott,

I'd try something like this (can't test it here, since I don't have a SQL server):

Public Sub Test()
Dim q As QueryDef
Dim varDBname As String

varDBname = "whateveryouwant"
For Each q In CurrentDb.QueryDefs
  If q.Type = dbQSQLPassThrough Then
    q.Connect = "ODBC;DRIVER=SQL Server;SERVER=DIMENSIONS;UID=scott;PWD=password;DATABASE=" & varDBname
  End If
Next
End Sub

Hope this helps you,
   Erwin
0
 
LVL 54

Expert Comment

by:nico5038
Comment Utility
Just make a function using:

function fncSetConnectTest
dim qd as querydef

set qd = currentdb.querydefs("your queryname")
qd.connect = "the connection string you need for test"

end function

 and

function fncSetConnectProd
dim qd as querydef

set qd = currentdb.querydefs("your queryname")
qd.connect = "the connection string you need for prod"

end function


After running this the connection will be saved.

Nic;o)
0
 
LVL 1

Author Comment

by:scottsanpedro
Comment Utility
Excellant solution....

Works wonderful

Thanks for you time

Scott
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now