473,499 Members | 1,483 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_20071029_104206.xls

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

Thanks.
Oct 29 '07 #1
7 3882
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
3445
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...
6
3199
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"...
2
1400
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...
7
2197
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
2091
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
2246
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...
10
3408
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...
4
2639
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
1873
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...
11
2260
by: Dijkstra | last post by:
Hi folks! First, this is the code I'm using to expose the problem: ------------------------------------------------------------------ #include <functional> #include <string> #include...
0
7128
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,...
0
7006
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6892
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...
0
7385
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5467
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,...
1
4917
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3096
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...
0
3088
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
661
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.