Solved

Access 2007 MACRO: Transfer Spread Sheet

Posted on 2013-11-04
7
651 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 119

Expert Comment

by:Rey Obrero
Comment Utility
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
Comment Utility
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
Comment Utility
It works if I use the actual computer name and username in the path
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
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
Comment Utility
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 119

Expert Comment

by:Rey Obrero
Comment Utility
add this line after the transferspreadsheet  command


msgbox "Table nameOftable was updated!"
end function
0
 

Author Comment

by:CMILLER
Comment Utility
It worked, Thanks!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 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

16 Experts available now in Live!

Get 1:1 Help Now