Solved

ODBC Connect Str

Posted on 2002-03-07
3
427 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

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…
Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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