Solved

How use current user for saved import

Posted on 2014-01-02
4
429 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
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.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

776 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