Solved

ODBC Connect Str

Posted on 2002-03-07
3
424 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
ID: 6846939
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
ID: 6846942
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
ID: 6846969
Excellant solution....

Works wonderful

Thanks for you time

Scott
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

863 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

18 Experts available now in Live!

Get 1:1 Help Now