[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How use current user for saved import

Posted on 2014-01-02
4
Medium Priority
?
472 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
[X]
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
  • 2
4 Comments
 
LVL 25

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 25

Accepted Solution

by:
chaau earned 2000 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 39

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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
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…

656 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