Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How use current user for saved import

Posted on 2014-01-02
4
437 Views
Last Modified: 2014-01-03
This is what I see in a saved import:

C:\Users\Steve\Desktop\Download.csv

But I want to change it to be the current user's desktop, not mine.

What do I change it to?

--Steve
0
Comment
Question by:SteveL13
  • 2
4 Comments
 
LVL 24

Expert Comment

by:chaau
ID: 39752548
In Access VBA you can use Environ("USERPROFILE") to get the current user home folder. See Office help for more information.
In your case, the path will be:
Dim path AS String
path = Environ("USERPROFILE") & "\Desktop\Download.csv"

Open in new window

0
 

Author Comment

by:SteveL13
ID: 39752633
I'm probably not communicating.  I need to somehow get your information into the setup of the saved import.  Please see the attached file.
Clip1.jpg
0
 
LVL 24

Accepted Solution

by:
chaau earned 500 total points
ID: 39752692
Yes, you can modify the saved import. Place this code into your VBA console for the Button click event:
Private Sub Command1_Click()
spec = 99 'Or any other unreasonably large number of your choice
For i = 0 To Access.CurrentProject.ImportExportSpecifications.Count - 1
    If Access.CurrentProject.ImportExportSpecifications(i).Name = "Download" Then
        spec = i
        Exit For
    End If
Next
If spec = 99 Then
    Call MsgBox("Critical Error.  Import Specification Not Found.  This process will now exit.", vbCritical)
    Exit Sub
End If
strXML = Access.CurrentProject.ImportExportSpecifications(spec).XML

Dim strImportFile As String
strImportFile = Environ("USERPROFILE") & "\Desktop\Download.csv"


'Find the delimiters of the current path string
i = InStr(strXML, "ImportExportSpecification Path=")
If i = 0 Then i = InStr(strXML, "ImportExportSpecification Path = ")
'First double quote after that
i = InStr(i, strXML, Chr(34))
'Second double quote after that
j = InStr(i + 1, strXML, Chr(34))
strReplace = Mid(strXML, i + 1, j - i - 1)
strXML = Replace(strXML, strReplace, strImportFile)

Access.CurrentProject.ImportExportSpecifications(spec).XML = strXML

' Put here the code that I have specified in the answer for your previous question:
docmd.RunSavedImportExport("Download")
End Sub

Open in new window

0
 
LVL 35

Expert Comment

by:PatHartman
ID: 39754048
If you are trying to create an import spec to define how a text file is formatted, start again.  Go through the import process manually and before you get to the end, press the Advanced button and choose to save the import spec.  Then in your TransferText method, you refer to the saved import spec.  The path to the file is a separate parameter so you will need some way to determine where the file is located.  Depending on how my users want to work, I might give them a setup form that they use to define paths to where they want to keep their input/output files or I might prompt just ahead of running the import if they want to be completely flexible.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question