Odbc/sql server access in Excel - repeatedly asking for password

rossbritton26

New Member
Joined
Jul 28, 2011
Messages
33
Hi,

I have created a macro which creates a SQL Server connection and returns data as requested - this works fine, however, my macro involves running the same code a number of times - also works fine, just with different connections - still all working!

However, because I am making a number of connections I am prompted for a password each time the macro creates one the connections.
The password is always the same, is there I way I can maybe add to my code below so it won't require me to input the password each time, e.g. maybe the password somewhere in the code?

Code:
    With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array(Array( _
        "ODBC;DRIVER=SQL Server;SERVER=(my server name here);UID=(user name here);;APP=2007 Microsoft Office system;WSID=2FDCZ2J;DATABASE=" & strDBName)), Destination:=Range("$A$1")).QueryTable
        .CommandText = Array("sql query here"")
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = True
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .SourceConnectionFile = _
        "C:\Users\" & Application.UserName & "\AppData\Roaming\Microsoft\Queries\" & strDBName & ".dsn"
        .ListObject.DisplayName = "Table_" & strDBName & "_(table name here)"
        .Refresh BackgroundQuery:=False
    End With
Thanks.
 

mole999

Moderator
Joined
Oct 23, 2004
Messages
9,899
I think in here somewhere

"ODBC;DRIVER=SQL Server;SERVER=(my server name here);UID=(user name here);;APP=2007 Microsoft Office system;WSID=2FDCZ2J;DATABASE=" & strDBName)), Destination:=Range("$A$1")).QueryTable

you need

Password=, well the variant that works with server / access, looks like it is missing between the double semi colons
 

rossbritton26

New Member
Joined
Jul 28, 2011
Messages
33
Thanks for the response mole999,

I did try that originally, after reading your response I searched again and found an example where Pwd was used, not Password.

This seemed to work!

Thanks for your prompt :)
 

Forum statistics

Threads
1,082,137
Messages
5,363,348
Members
400,729
Latest member
Lisa McConachy

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top