473,566 Members | 3,307 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Copy function on Output to file

benchpolo
142 New Member
Expand|Select|Wrap|Line Numbers
  1. Function outfile()
  2.     Dim stbl As String
  3.     stbl = "Contact"
  4.     DoCmd.OutputTo acOutputTable, stbl, acFormatXLS, "c:\temp\contact_" & Format(Now(), "yyyymmdd") & "_" & Format(Time(), "hhmmss") & ".xls"
  5.     MsgBox "File Exported"
  6. End Function
  7.  
Exported Filename: contact_2007102 9_104206.xls

Question? How do I copy (VBA code) the Exported filename to a different location?

Thanks.
Oct 29 '07 #1
7 3888
missinglinq
3,532 Recognized Expert Specialist
How do I copy (VBA code) the Exported filename to a different location?
You can change your code slightly, like this:
Expand|Select|Wrap|Line Numbers
  1. Function outfile()
  2. Dim stbl As String
  3. Dim FileName as String
  4.  
  5. stbl = "Contact"
  6.  
  7. FileName = "contact_" & Format(Now(), "yyyymmdd") & "_" & Format(Time(), "hhmmss") & ".xls"
  8.  
  9. DoCmd.OutputTo acOutputTable, stbl, acFormatXLS, "c:\temp\" & FileName
  10.  
  11. 'Copy to a different location
  12.  DoCmd.OutputTo acOutputTable, stbl, acFormatXLS, "d:\temp\" & FileName
  13.  
  14.  
  15. MsgBox "File Exported"
  16. End Function
  17.  
and you'd have your filename as it was for the output file, right down to the second. But where do want to "copy" it to?

Linq ;0)>
Oct 29 '07 #2
benchpolo
142 New Member
To another location like a backup external hardrive.
Oct 29 '07 #3
benchpolo
142 New Member
What about file scripting? (see code below). With this code it is basically copying file from one source (c:\temp) to a new destination (c:\temp\txt), but i am getting error "Path not found". Thanks.
Expand|Select|Wrap|Line Numbers
  1. Function copyfile()
  2.     Dim fs As Object
  3.     Dim oldPath As String, newPath As String
  4.  
  5.     oldPath = "C:\Temp\contact_" & Format(Now(), "yyyymmdd") & "_" & Format(Time(), "hhmmss") & ".xls"
  6.     newPath = "C:\Temp\txt\contact_" & Format(Now(), "yyyymmdd") & "_" & Format(Time(), "hhmmss") & ".xls"
  7.  
  8.     Set fs = CreateObject("Scripting.FileSystemObject")
  9.  
  10.     fs.copyfile oldPath & "\" & "contact_" & Format(Now(), "yyyymmdd") & "_" & Format(Time(), "hhmmss") & ".xls", newPath & "\" & "contact_" & Format(Now(), "yyyymmdd") & "_" & Format(Time(), "hhmmss") & ".xls"
  11.  
  12.     Set fs = Nothing
  13. End Function
  14.  
Oct 29 '07 #4
missinglinq
3,532 Recognized Expert Specialist
So you don't want to copy the filename to another location, as you said, but rather copy the file to another location. Go back to my previous post, where I've edited my code. Line # 12 repeats your operation, sending the file to the D drive and same subfolder as the original. You can modify this path to suit your needs. That's all you need to do.

Linq ;0)>
Oct 29 '07 #5
Rabbit
12,516 Recognized Expert Moderator MVP
This is more efficient for copying a file:
Expand|Select|Wrap|Line Numbers
  1. FileCopy "Source Path", "Destination Path"
  2.  
This is slightly more efficient as far as formatting the date goes:
Expand|Select|Wrap|Line Numbers
  1. Format(Now(), "yyyymmdd_hhmmss")
  2.  
Oct 29 '07 #6
benchpolo
142 New Member
I think I will stick to your suggestion.. I don't to do tidious coding.. like the old saying "Work Smart Not Hard".. Thanks for all the inputs! =)
Oct 29 '07 #7
Rabbit
12,516 Recognized Expert Moderator MVP
Good luck.
Oct 29 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
3456
by: Anna | last post by:
Hi all. I am trying to write a stylesheet that will structure the input HTML file in the following way: For each heading of level n it needs to enclose the heading and all its content until the next heading of the same level within the level tag. Example input file:
6
3205
by: ma740988 | last post by:
There's no way to use the STL algorithm copy to print an outfile (essentially an ofstream)? So now: int main() { std::ifstream InFile( "exercise15.txt"); std::ofstream ToFile( "NewFile.txt" ); //////////////////////////// // Alternative 1
2
1407
by: wutongjoe | last post by:
Hi all, I was writting 2 programs in c++ using linux.Say,one is app1 and another one is app2,the app1 will generate 100 random numbers and then print them on the standard output,and then the app2 needs to copy the numbers from the standard output to its int array by doing this way: $ app1|app2 (a pipe ? I am a newbi,and not sure how to call...
7
2203
by: Harag | last post by:
Hi all If I create an object with the following: var ob1 = new objMyDefinedObject(); then I assign it to a new variable. var ob2 = ob1
11
2099
by: F. Michael Miller | last post by:
I'd like to copy the listing of a directory (& sub directories) to a text file in vb.net. I'm looking for teh equivilant of the DOS command dir /s > TargetFile.txt. Thanks!
7
2257
by: Harrie | last post by:
Hi group, I want to indent existing XML files so they are more readable (at least to me). At this moment I'm looking at the XML files OpenOffice.org's Writer application produces in it's zipped "SXW" format (and they're one line, probably to save space, which I find hard to read). At first I thought I was going to do it with sed/awk or...
10
3416
by: JurgenvonOerthel | last post by:
Consider the classes Base, Derived1 and Derived2. Both Derived1 and Derived2 derive publicly from Base. Given a 'const Base &input' I want to initialize a 'const Derived1 &output'. If the dynamic type of 'input' is Derived1, then 'output' should become a reference to 'input'. Otherwise 'output' should become a reference to the (temporary)...
4
2647
by: Herman.Schultz | last post by:
Hi, How can I use iostream library in c++ to copy a file from i th byte to an output file? Thank you.
1
1876
by: ajc308 | last post by:
I'm attempting to sort the <file>s within each <directory> in my XML according to their file extension, then write out the resulting sorted data back to XML format. I had it working before, and when I opened up the file the next day, the XSL behaved completely different. I don't know if I accidentally changed something, but I can't see any...
11
2273
by: Dijkstra | last post by:
Hi folks! First, this is the code I'm using to expose the problem: ------------------------------------------------------------------ #include <functional> #include <string> #include <iostream> using namespace std;
0
7673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7893
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8109
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7645
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6263
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.