这就是我所拥有的:
Private Sub EthosRpt_Click()
DoCmd.OpenQuery "EthosSessions"
DoCmd.TransferText acExportDelim, , "EthosSessions", "C:\Users\JDoe\Desktop\EthosRpt.csv", True
End Sub
它适用于我的用户帐户(我的用户帐户= JDoe)。如何让它适用于任何当前用户?
答案 0 :(得分:1)
尝试“%USERPROFILE%\ Desktop \ EthosRpt.csv”
像: DoCmd.TransferText acExportDelim ,,“EthosSessions”,“%USERPROFILE%\ Desktop \ EthosRpt.csv”,True
答案 1 :(得分:0)
首先获取用户名作为字符串并替换用户名
Dim strDisplayName as string
Set objAD = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objAD.UserName)
strDisplayName = objUser.DisplayName
大于
DoCmd.TransferText acExportDelim, ,
"EthosSessions","C:\Users\" & strDisplayName & "\Desktop\EthosRpt.csv", True
答案 2 :(得分:0)
尝试:
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