how to change userid/password in multiple queries simultaneously
Results 1 to 3 of 3

Thread: how to change userid/password in multiple queries simultaneously
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Feb 2017
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default how to change userid/password in multiple queries simultaneously

    I have a workbook with several queries to an external db. For all of them, I let Excel save both UserId and Password (not a big security concern, at the moment).
    Quite often I need to run the same set of queries against different db schema, that is, by logging in using different UserId/Password (s).
    Is there a way (even with VBA) to set the same UserId/Password for all my queries simultaneously , without having to modify each query's properties?

    Thanks in advance

  2. #2
    Moderator mole999's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    9,817
    Post Thanks / Like
    Mentioned
    16 Post(s)
    Tagged
    2 Thread(s)

    Default Re: how to change userid/password in multiple queries simultaneously

    go global declaration
    Last edited by mole999; Oct 20th, 2017 at 11:11 AM.
    • Yes I know there are better ways to do it. I just wish I knew them. - 97, 2003, 2007, 2010, 2013, 2016 & 2019
    • I wear my ignorance openly, excel is not my chosen career, its a means to an ends
    • Posting Guidelines Want to post well laid out questions and answers Translate Excel Versions
      Code:
      [CODE ]Put Your Code[/ CODE]
    • Settings > General Settings (on the left) scroll to the bottom, > Miscellaneous Options > Use ENHANCED
    • X-Posting Guidelines Rule 13 > CHART STUFF

  3. #3
    New Member
    Join Date
    Feb 2017
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: how to change userid/password in multiple queries simultaneously

    Thanks for your reply. However, I don't see how global declaration (of what?) could accomplish what I'm looking for.
    Anyhow, After some tries, I put together the following VBA code, that seems to do what I need.Sub UpdateCredentials(ByVal userid AsString,ByVal userpwd AsString)

    Dim ConnString AsString
    Dim newString AsString
    Dim ws As Worksheet

    ForEach ws In Worksheets
    For o =1To ws.ListObjects.Count
    ConnString
    = ws.ListObjects(o).QueryTable.Connection
    i1
    = InStr(1, ConnString,"UID", vbTextCompare)
    i2
    = InStr(1, ConnString,"PWD", vbTextCompare)
    If i2 =0Then i2 = i1 +2
    i3
    = InStr(i2, ConnString,";", vbTextCompare)

    newString
    = Left(ConnString, i1 +3)+ userid +";PWD="+ userpwd +";"+ Right(ConnString, Len(ConnString)- i3)

    ws
    .ListObjects(o).QueryTable.Connection = newString

    Next o
    Next
    End Sub

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •