Solved

How use current user for saved import

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

896 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

15 Experts available now in Live!

Get 1:1 Help Now