Solved

How use current user for saved import

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

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
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…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now