A query for all users/domains?

Damian86

New Member
Joined
Jun 30, 2014
Messages
47
Hi,
I've created a report that acquires accounting information from the server. It works fine for me but I want the file to work for other users as well. Other users work in different domains.
My query code is a standard "recorded" query that I created via Microsoft Query:

Code:
Sub Kwerenda_Płatnosci(Optional F As Integer)

    With ActiveSheet.ListObjects.Add(SourceType:=0, Source:="ODBC;DRIVER=SQL Server;SERVER=MYSERVER;UID=ksieg2;APP=Microsoft Office 2010;WSID=KSIEG02-L;DATABASE=EP_15;Trusted_Connection=Yes", Destination:=Range("$A$1")).QueryTable
        .CommandText = ("SELECT Platnosci.Podmiot, Platnosci.PodmiotType, Platnosci.DokumentType, Platnosci.Bufor, Platnosci.Termin, Platnosci.KwotaValue, Platnosci.Opis, Platnosci.NumerDokumentu, Platnosci.DataDokumentu, Platnosci.Kierunek" & Chr(13) & "" & Chr(10) & "FROM ep15_opisie.dbo.Platnosci Platnosci" & Chr(13) & "" & Chr(10) & "WHERE (Platnosci.PodmiotType='Kontrahenci')")
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .ListObject.DisplayName = "Kwerenda_Platnosci"
        .Refresh BackgroundQuery:=False
    End With
End Sub

So my server username is "ksieg02". When I give the file with a query to other users outside that use another domain, there is a warning that the data couldn't be refreshed and there is a box prompting for the password. Is it possible to write the code for a universal connection?
I used this technique and I thought that code would "disguise" itself as me so that other users use my login and my trusted connection :) I'm sorry if it was a stupid idea :)
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,214,784
Messages
6,121,535
Members
449,037
Latest member
tmmotairi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top