Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ODBC Connect Str

Posted on 2002-03-07
3
Medium Priority
?
441 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 5

Accepted Solution

by:
TheMek earned 400 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

597 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