Update FROM in CommandText

excelaudio

New Member
Joined
Nov 4, 2015
Messages
8
I have a spreadsheet that is used by different users. The spreadsheet defaults to the user's desktop folder when pulling from an Access database. My connections get updated appropriately with the VBA code I inherited, but it doesn't update the user's profile in the following code:

Note: this is the code in one of the 4 connections in the command text box:

Code:
SELECT qry_Contracts.Contract, qry_Contracts.LOB,qry_Contracts.State,qry_Contracts.Region,qry_Contracts.Membership,qry_Contracts.DEN
FROM 'c:\users\"username"\desktop\Daily Model Import Folder\Out of Compliance Database.accb'.qry_Contracts qry_Contracts
ORDER BY qry_Contracts.Contract

I need the FROM "username" to automatically read the user's profile instead of it being hard coded.

Thanks for any help you can provide as I have googled everything under the sun and tinkered around with no success.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Unfortunately, that did not help. Is there any way to have the FROM statement in the CommandText read a specific pathway that can reference a computer username? That would be the ideal solution.
 
Upvote 0
Difficult to help with the code without seeing more of yours, but perhaps something like the following?
Code:
strSelect = "SELECT qry_Contracts.Contract, qry_Contracts.LOB,qry_Contracts.State,qry_Contracts.Region,qry_Contracts.Membership,qry_Contracts.DEN " & _
"FROM '" & "c:\users\" & Environ("username") & "\desktop\Daily Model Import Folder\Out of Compliance Database.accb'.qry_Contracts qry_Contracts " & _
"ORDER BY qry_Contracts.Contract;"
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.Open sConnString
Set rs = conn.Execute(strSelect)
 
Upvote 0

Forum statistics

Threads
1,214,400
Messages
6,119,288
Members
448,885
Latest member
LokiSonic

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