问题
This is what I have:
Private Sub EthosRpt_Click()
DoCmd.OpenQuery "EthosSessions"
DoCmd.TransferText acExportDelim, , "EthosSessions", "C:\Users\JDoe\Desktop\EthosRpt.csv", True
End Sub
It works with my user account (where my user account = JDoe). How do I get it to work for ANY current user?
回答1:
Try with:
Private Sub EthosRpt_Click()
Dim FileName As String
DoCmd.OpenQuery "EthosSessions"
FileName = Environ("UserProfile") & "\Desktop\EthosRpt.csv"
DoCmd.TransferText acExportDelim, , "EthosSessions", FileName, True
End Sub
回答2:
try "%USERPROFILE%\Desktop\EthosRpt.csv"
like: DoCmd.TransferText acExportDelim, , "EthosSessions", "%USERPROFILE%\Desktop\EthosRpt.csv", True
回答3:
first get the username as string and replace the username
Dim strDisplayName as string
Set objAD = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objAD.UserName)
strDisplayName = objUser.DisplayName
than
DoCmd.TransferText acExportDelim, ,
"EthosSessions","C:\Users\" & strDisplayName & "\Desktop\EthosRpt.csv", True
来源:https://stackoverflow.com/questions/50595765/how-to-specify-current-user-desktop-for-docmd-transfertext