Solved

Access 2007 MACRO: Transfer Spread Sheet

Posted on 2013-11-04
7
708 Views
Last Modified: 2013-11-05
I have a Transfer Spread Sheet macro that imports an excel file and I am wanting to create a file name path that will work for multiple users on my network and off my network.

So, here is what I have tried and it didnt work.

"\\%COMPUTERNAME%\Users\%username%\Documents\Import\file name.xls"
0
Comment
Question by:CMILLER
  • 4
  • 3
7 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39622511
try doing this way..
in your macro add a single action (RunCode)
Action
RunCode


Function Name ImportXL()


now create a function in a regular VBA module

Function ImportXL()

dim strFile as string
strFile="\\%COMPUTERNAME%\Users\%username%\Documents\Import\file name.xls"

'complete this line for the TransferSpreadsheet command

docmd.transferspreadsheet acimport,8, "NameOfTable", strFile, true,"NameOfsheet!"

end function
0
 

Author Comment

by:CMILLER
ID: 39622763
It doesnt like this line even though I added the name of the TABLE and the Name of the Sheet

docmd.transferspreadsheet acimport,8, "NameOfTable", strFile, true,"NameOfsheet!"
0
 

Author Comment

by:CMILLER
ID: 39622791
It works if I use the actual computer name and username in the path
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 39622942
change this line

strFile="\\%COMPUTERNAME%\Users\%username%\Documents\Import\file name.xls"

with

strFile=environ("userprofile") & "\Documents\Import\file name.xls"
0
 

Author Comment

by:CMILLER
ID: 39624620
That did it!!

I know that wasnt part of the question but how do I add a notification to the module that shows that the table updated?

Thanks
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39624698
add this line after the transferspreadsheet  command


msgbox "Table nameOftable was updated!"
end function
0
 

Author Comment

by:CMILLER
ID: 39624714
It worked, Thanks!
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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
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 …

749 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