• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5697
  • Last Modified:

how to bypass the SQL login prompt in Microsoft Access using VBA

When I open my access database that has linked tables (via ODBC connection under System DSN) to SQL Server, I automatically have a form open at Startup.  This form contains data from the linked SQL table.  So when then form opens, I get a login prompt to enter my user name and password.  Which I have to enter each time I open my access database (one time only during each opening).  So I created a VBA function that I use in my "AutoExec" macro to attempt to pass this login info.  The macro does not fault out when I open the access database, but I am still prompted to enter the login credentials that I would like to pass using VBA.  How can I automatically send the login credentials?  Thanks.

Public Function Autoconnect()

Dim cnn1 As Object
Dim strCnn1 As String

strCnn1 = "Provider=SQLOLEDB;Data Source=xxx.x.x.xx;Initial Catalog=QA;User ID=test;Password=;"
Set cnn1 = CreateObject("ADODB.Connection")
cnn1.ConnectionString = strCnn1
cnn1.Open

end function
0
sxxgupta
Asked:
sxxgupta
  • 3
  • 2
1 Solution
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
<<When I open my access database that has linked tables >>

  You have to either:

A. provide the username and password as part of the DSN

B. provide the username and password as part of each tables connect property.

C. When creating the linked table, check the "save password" check box in the dialog.  Access will cache the credentials used.  There is no way to view or change these.  For a password change, you would need to delete the table link and re-create it.

Jim.
0
 
sxxguptaAuthor Commented:
How do I do option B. via VBA because option C will be very tedious as I have a lot of linked tables.
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
Take a look at the following article:

http://www.accessmvp.com/DJSteele/DSNLessLinks.html

Which has a routine called FixConnections().  You'll find it easy to modify that and add the username and password to the connect string using that procedure.

Jim.
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
Note on the above: it actually deletes and recreates the tabledefs().  If you go that route, make sure you have a backup.

The important thing however is to see how he's looping through the TableDefs Collection.

 In your case, all you need to do is append the USERNAME and PASSWORD arguments to the connect string and update the connect property assuming you still wish to continue using the DSN.

Jim.
0
 
sxxguptaAuthor Commented:
Thanks Jim.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now