Access 2K / Pass Trought Query?

I am using MS Access 2000 with backend SQL Server 2000.
I created a passthrough query that basically just executes a stored procedure on the SQL Server. But each time I run the query it brings to the dialogue box to select the data source. How can I have this info saved?
LVL 1
Jess31Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jmoss111Commented:
you'll need to fill the connect string parameter in the pass through querydef
answer_dudeCommented:
Make sure your connection string is fully specified, including the password, as part of your query properties.

Open your query in design mode, click properties, set your ODBC connection string.

For SQL Server your connection string should be something like this:

ODBC;DRIVER=SQL Server;SERVER=servername;UID=userid;PWD=password;DATABASE=dbname;NETWORK=network;TABLE=tablename

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jmoss111Commented:
the code below will grab the username and use that to build the connectstring
Private Declare Function GetUserName Lib "ADVAPI32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Public Const strConnect1 = "ODBC;DRIVER={SQL SERVER};SERVER=999.999.999.999\SQLEXPRESS;DATABASE=MyDb;UID="

Public Const strConnect2 = ";PWD=mypw;"

Public Function GetCurrentUserName() As String
On Error GoTo Err_GetCurrentUserName
 Dim lpBuff As String * 25
 Dim ret As Long, Username As String
   ret = GetUserName(lpBuff, 25)
   Username = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
   GetCurrentUserName = Username & ""
   gUsrNm = GetCurrentUserName
   
  
   
Exit_GetCurrentUserName:
    Exit Function

Err_GetCurrentUserName:
        MsgBox Err.Description
        Resume Exit_GetCurrentUserName
End Function


public gUserNm AS String
Public Function GetCurrentUserName() As String
On Error GoTo Err_GetCurrentUserName
 dim db as dao.database
 set db = currentdb
 Dim lpBuff As String * 255
 Dim ret As Long, Username As String
   ret = GetUserName(lpBuff, 255)
   Username = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
   GetCurrentUserName = Username & ""
   gUsrNm = GetCurrentUserName

db.QueryDefs("qptMyPassthru").Connect = gstrConnect1 & gUsrNm & strConnect2
Exit_GetCurrentUserName:
    Exit Function

Err_GetCurrentUserName:
        MsgBox Err.Description
        Resume Exit_GetCurrentUserName
End Function

Open in new window

jmoss111Commented:
if you need help with a connect string or you're using windows authentication instead of mixed mode you can reference http://www.connectionstrings.com/
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.