Question

Macro TransferText import from XXX.XXX.mmddyy.hhmm.TXT, Access 2007,

Asked by: marellano

i'm attempting to import a text file using TransferText in a Macro.  The file being imported contains a date timestamp in the filename (P01.FLG.mmddyy.hhmm.TXT).  In the TransferText parameteres, I've attempted to use different variations of the "format function" in the File Name field:
(" & Format(Date()-1,"mmddyy") & "." & Format(Date(),"hhmm") & ".TXT")

However, the main problem seems to be that TransferText does not recognize the multiple periods in the filename being imported (i.e P01.FLG.mmddyy.hhmm.TXT).  I get an error message stating that it cannot fine the file name.  However, the function works fine when I remove the extra "periods" and the "hhmm" on the filename (i.e P01FLGmmddyy.TXT).  

What I really require is to be able to import the file that contains the CURRENT DATE in the timestamp portion of the filename.  So if the file name is P01.FLG.082608.1200.TXT, I need the import to only verify the mmddyy of the file and import it. Is this possible??

PLEASE NOTE THAT AT THIS TIME, I'M ONLY INTESTED IN A SOLUTION USING TRANSFERTEXT MACRO.


="C:\Directory\" & Format(Date(),"mmddyy") & ".TXT"
                                  
1:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-08-26 at 09:12:11ID24683738
Tags

Ms Access 2007

,

TransferText macro

,

file import

,

format function

Topics

Microsoft Access Database

,

Access Coding/Macros

,

Access Architecture/Design

Participating Experts
1
Points
250
Comments
28

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. specification in TransferText
    Hi, I am trying to debug an application developed(by somebody else) in vba in Access that does a lot of import and export of data to and fro access. While using the Transfertext method, one of the parameters that it accepts is the specificiation in which the data needs to ...
  2. Running a macro or such to execute TransferText from ADO
    Hi, As part of a software package I'm writing I need to import a large text file into an access table. I'm developing using BCB 6 and ADO components. The target audience for the package are running anything from a 200MHz Pentuim upwards. Parsing the textfile line by line an...
  3. TransferText
    I am trying to import a text file from an ftp site but cant seem to get the proper wording. Its in a Macro TransferText action. I have... ftp://cmcgregor:pass2000@148.123.2.130/data/SAS/Starii_Extract/cmcgregor/FSAsNotDelivered.txt in the file name field but it doesnt seem ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: jimpenPosted on 2009-08-26 at 10:45:21ID: 25190244

See what happens if you wrap it double-quote marks.

=CHR(34) &  "C:\Directory\" & Format(Date(),"mmddyy") & ".TXT" & CHR(34)

                                              
1:

Select allOpen in new window

 

by: marellanoPosted on 2009-08-26 at 11:58:26ID: 25190982

jimpen,
i entered:
=Chr(34) & "C:\Directory\EXPERIAN TRIGGERS\DATA\" & Format(Date(),"mmddyy") & ".TXT" & Chr(34)
and got the following error eventhough the file is does have an .txt extension:
you cannot import this file...you cannot import a text file unless it has one of these extensions: TXT,CVS...



 

by: jimpenPosted on 2009-08-26 at 12:31:31ID: 25191327

From Access 97 SP1 (?) on they have restricted the extensions that you can import with the transfertext methods. And the Acc/JET engine apparently isn't recognizing the multiple periods in the name. Its reading "P01.FLG.082608.1200.TXT" as "P01.FLG" and not liking the extension.

The only suggestion is doing a filecopy to rename the file and then do the import. The only other thing would be to roll your own import.


ACC2000: How to Import a Text File That Has an Extension That Access Does Not Recognize
http://support.microsoft.com/kb/306144

Public Function RenameFiles_Q(OrigFileName As String, FullPath As String)
 
Dim NewFileName As String
 
NewFileName = "\" & Replace(Left(OrigFileName, Len(OrigFileName) - 4), ".", "") & ".txt"
 
FileCopy FullPath & "\" & OrigFileName, FullPath & NewFileName
Kill FullPath & "\" & OrigFileName
 
DoCmd.TransferText
 
End Function

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:

Select allOpen in new window

 

by: jimpenPosted on 2009-08-26 at 12:41:31ID: 25191425

Oh -- the workaround in that link to edit the registry no longer works. I just haven't been able to find a newer version of the same thing for other versions.

 

by: marellanoPosted on 2009-08-26 at 12:50:36ID: 25191513

hmmm...let me play with this idea and get back to you jimpen.

 

by: jimpenPosted on 2009-08-26 at 12:56:47ID: 25191576

Not a problem.

 

by: marellanoPosted on 2009-08-26 at 15:47:31ID: 25193043

jimpen,

I'm not too familiar with VB but I tried the filecopy/rename by creating a new module and entering the VB code.  First, I didn't do anything when I ran it with the exception of prompting me for a macro name. Secondly, I'm assuming that even if this code worked that it seems that it's dependent on that the imported file name is always the same, true??  If so, this would not work since the file names will have a different date/time stamp on the daily basis.


 

Public Function RenameFiles_Q(OrigFileName As String, FullPath As String)
 
Dim NewFileName As String
 
NewFileName = "\" & Replace(Left("C01398.P01.NTC.082609.1230.TXT", Len("C01398.P01.NTC.082609.1230.TXT") - 4), ".", "") & ".txt"
 
FileCopy FullPath & "\" & "C01398.P01.NTC.082609.1230.TXT", FullPath & "082609.TXT"
Kill "C:\Directory" & "\" & "C01398.P01.NTC.082609.1230.TXT"
 
DoCmd.TransferText
 
End Function
 
 
Sub Import_Trigger_Master_Test()
 
End Sub
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:

Select allOpen in new window

 

by: marellanoPosted on 2009-08-26 at 16:01:37ID: 25193155

sorry, this is how i entered the VB code:

Public Function RenameFiles_Q(OrigFileName As String, FullPath As String)
 
Dim NewFileName As String
 
NewFileName = "\" & Replace(Left("C01398.P01.NTC.082609.1230.TXT", Len("C01398.P01.NTC.082609.1230.TXT") - 4), ".", "") & ".txt"
 
FileCopy "C:\Directory" & "\" & "C01398.P01.NTC.082609.1230.TXT", "C:\Directory" & "082609.TXT"
Kill "C:\Directory" & "\" & "C01398.P01.NTC.082609.1230.TXT"
 
DoCmd.TransferText
 
End Function
 
 
Sub Import_Trigger_Master_Test()
 
End Sub
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:

Select allOpen in new window

 

by: jimpenPosted on 2009-08-26 at 16:53:52ID: 25193443

I'm on EE mobile, for the evening,  so I can't really see the code snippet. I'll look in the morning.

 

by: marellanoPosted on 2009-08-26 at 17:04:22ID: 25193481

thanks jimpen.

 

by: jimpenPosted on 2009-08-27 at 05:37:44ID: 25197240

There are several ways to do this.

You can have a form with text fields where you would put the current days info and then have it renamed.
-----------------------------------------
RenameFiles_Q Me.FileNameTxtBox.Value, Me.FilePathTxtBox.Value
-----------------------------------------

Or you could use a preset path that you dump the files into. Then you hard code the path in the function. Then you can have Access do a DIR command to find the file(s) and rename them.

Or in the macro it would be a RunCode command.

BTW, you can right-click a Macro in the database window and have it converted to VBA.

Public Function RenameFiles_Q(OrigFileName As String, FullPath As String)
 
Dim NewFileName As String
 
NewFileName = "\" & Replace(Left(OrigFileName, Len(OrigFileName) - 4), ".", "") & ".txt"
 
FileCopy FullPath & "\" & OrigFileName, FullPath & NewFileName
Kill FullPath & "\" & OrigFileName
 
'This is the beginning of the TransferText.
'DoCmd.TransferText ........
End Function

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:

Select allOpen in new window

 

by: marellanoPosted on 2009-08-27 at 10:16:36ID: 25200566

hi jimpen...didn't forget about you.  let me please get back to you later today.  Thanks again.

 

by: marellanoPosted on 2009-08-27 at 14:15:53ID: 25202801

hi jimpen,
I tested the RenameFile code portion and I'm getting a runtime error '70'; permission denied.

I created a function from the VB script you provided and ran it on a Macro unsing the RunCode command (please see attached screeprint).  I entered the filename and path which I then got the error when the macro ran (please see attached screeprint).  Any ideas?

Also, although the RenameFile function seems like a nice option, I believe that it's only going to work if the filename entered is always the same. I don't have a problem with this as long as I'm able to have the custom function grab any text file that it sees in the dump directory. Is this feasible??

My objective is to be able to automate the file import as mentioned. I couldn't use this custom function if it will not allow for any text file to be grabbed.

 

by: jimpenPosted on 2009-08-27 at 14:46:18ID: 25203042

Try this on.

You can put it in a module window and then just put the cursor in the body and hit <F5> to run it.

Public Function RenameFiles()
 
Dim NewFileName As String
Dim OrigFileName As String
Dim FullPath As String
 
'The directory that you are dumpint your files in.
FullPath = "C:\Documents and Settings\MyUserID\My Documents\"
 
'You have to do the first Dir command before entering the _
 loop so that it isn't blank. I'm doing this on the pattern _
 matching to "P*.txt" files.
OrigFileName = Dir(FullPath & "P*.txt")
 
Do Until OrigFileName = ""
    'Replace the extra periods.
    NewFileName = Replace(Left(OrigFileName, Len(OrigFileName) - 4), ".", "") & ".txt"
    
    'If you want to see the the files it finds and the new file names _
     uncomment the lines below anf then hit <Ctrl>+G to get the debug/ _
     immediate window.
    'Debug.Print OrigFileName
    'Debug.Print NewFileName
    
    'Make sure that you only run this on a directory you are sure of.
    FileCopy FullPath & OrigFileName, FullPath & NewFileName
    Kill FullPath & "\" & OrigFileName
    
    'Once you fire the Dir command the first time, it will hold a _
     marker so any subsequent Dir will bring the next one back in the list.
    OrigFileName = Dir
Loop
 
End Function

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:

Select allOpen in new window

 

by: marellanoPosted on 2009-08-27 at 15:58:47ID: 25203414

I could't get the module to do anything?? I ran DIR at a command prompt on the directory where the file resides. Then ran the vb script on a module window.  Is this correct?

 

by: jimpenPosted on 2009-08-27 at 16:04:44ID: 25203449

Did you change the FullPath to the right directory? With a trailing backslash?

Does the >> OrigFileName = Dir(FullPath & "P*.txt") << match your file pattern?

What happens if you uncomment the debug.print lines? (Take off the apostrophe mark.)

 

by: marellanoPosted on 2009-08-27 at 16:21:24ID: 25203529

I still got the "permission denied".  I made the changes only on the following portion of the vb script (see below).  I ran the debug and it highlighted the "FileCopy FullPath & OrigFileName, FullPath & NewFileName" portion of the script.  

'The directory that you are dumpint your files in.
FullPath = "C:\Documents and Settings\...\"
 
'You have to do the first Dir command before entering the _
 loop so that it isn't blank. I'm doing this on the pattern _
 matching to "P*.txt" files.
OrigFileName = Dir("C:\Documents and Settings\...\" & "P*.txt")

                                              
1:
2:
3:
4:
5:
6:
7:

Select allOpen in new window

 

by: jimpenPosted on 2009-08-27 at 16:31:00ID: 25203564

The FullPath is a variable. You assign it the value once, and then use it as a substitute for having to type out or replace C:\Documents and Settings\...\ every single time.

And are you actually using "C:\Documents and Settings\...\" for the path? A path with three periods is not a valid path.  Let's try this. Make a directory in the root of your C: drive called "temp". Copy your files there.

Then run the code below exactly as written.


Public Function RenameFiles()
 
Dim NewFileName As String
Dim OrigFileName As String
Dim FullPath As String
 
'The directory that you are dumping your files in.
FullPath = "C:\Temp\"
 
'You have to do the first Dir command before entering the _
 loop so that it isn't blank. I'm doing this on the pattern _
 matching to "P*.txt" files.
OrigFileName = Dir(FullPath & "P*.txt")
 
Do Until OrigFileName = ""
    'Replace the extra periods.
    NewFileName = Replace(Left(OrigFileName, Len(OrigFileName) - 4), ".", "") & ".txt"
    
    'If you want to see the the files it finds and the new file names _
     uncomment the lines below anf then hit <Ctrl>+G to get the debug/ _
     immediate window.
    'Debug.Print OrigFileName
    'Debug.Print NewFileName
    
    'Make sure that you only run this on a directory you are sure of.
    FileCopy FullPath & OrigFileName, FullPath & NewFileName
    Kill FullPath & "\" & OrigFileName
    
    'Once you fire the Dir command the first time, it will hold a _
     marker so any subsequent Dir will bring the next one back in the list.
    OrigFileName = Dir
Loop
 
End Function

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:

Select allOpen in new window

 

by: marellanoPosted on 2009-08-27 at 16:57:52ID: 25203666

Unfortunately, I'm still getting the permission error.  I think that the script is acknowledging the path and filename but not able to copy and rename due to some persmission error??

Right, I'm not actually using actually using "C:\Documents and Settings\...\"  
I just shorten it here intentionally.  In any case, I now created a C:\Temp forder where I moved the txt file just to make it simple.  

Ok, so the FullPath is a variable which only entered once...understood...thank you.

Any thought on what I can do on the permission settings?  I do have full rights.

(I'll be leaving shortly)

 

by: jimpenPosted on 2009-08-27 at 17:08:54ID: 25203742

Are you an admin on your machine?

Add a line "msgbox "break"" like below.
-----------------------------------------------
'You have to do the first Dir command before entering the _
 loop so that it isn't blank. I'm doing this on the pattern _
 matching to "P*.txt" files.

msgbox "break"

OrigFileName = Dir(FullPath & "P*.txt")
-----------------------------------------------

When you get the popup hit <Ctrl> + <Break>. If it asks about code execution stopped click the <Debug> button. Then in the debug window (<ctrl>+G) put in ?Dir(FullPath & "P*.txt") and <enter> and see what you get. If you get an error then just put in ?FullPath and <enter>.

 

by: marellanoPosted on 2009-08-27 at 18:13:04ID: 25204303

Yes, I'm the admin.
Okay! it worked this time...the extra periods got removed from the original file...great!   =)

I then tried it without the msgbox and it worked as well.  So those this mean that the drop folder needs to be at the root of the C:\ drive??

We can continue this discussion tomorrow...thanks for your help!

 

 

by: jimpenPosted on 2009-08-28 at 07:30:23ID: 25208025

The dir function in Access is an older version. So it probably has a problem with the LFN  (Long File Names -- spaces and odd characters).

The one you may be able to get away with using is the ENVIRON("temp") as the path name. Put -- ? ENVIRON("temp")  in the debug window and hit <Enter>. If it comes back with something like TEMP=C:\DOCUME~1\Userid~1\LOCALS~1\Temp then when you save the files in use %TEMP%\P01....txt in the windows save dialog. Or however you get the files there.

Then
FullPath = ENVIRON("temp") & "\"

That way it will be relative to whoever uses the code, and you won't have to make a special directory.
 

 

by: marellanoPosted on 2009-08-28 at 12:02:42ID: 25210638

Hi jimpen, haven't had a chance to test the above alternative but I think either way would be fine.  

The only question I have at the moment is that if I run this solution to standalone, will it require to have to "manually" run the DIR in the drop folder everytime a new file is added?

Thanks again for all help!  very much appreciated!

 

by: marellanoPosted on 2009-08-28 at 12:04:31ID: 31620795

very thorough and patient!!

 

by: jimpenPosted on 2009-08-28 at 12:27:47ID: 25210847

The new version could be run from a macro as just RenameFiles.

As a larger so;ution, we could build a whole module that does the rename, import and stores the ones that have been imported.

 

by: marellanoPosted on 2009-08-28 at 15:13:28ID: 25211968

Right. That's a possibility.

By running the RenameFile module and the original TransferText together in a macro, it should take care of the rename and import portion.  Right? I can then create a query to archive the new imported data onto an archive table.  

One area I still need to come up with is the FTP portion.  The files that are going to be renamed and imported need to be transferred over from FTP into the drop folder.  I'd like to see if this can be automated in Access as well.  Would you be interested in assisting with this? Of course, I'd provide additional credits.  

I started looking at this example: http://www.mvps.org/access/modules/mdl0015.htm

Please let me know if you'd be interested in continuing.

great working with you jimpen!!

 

by: jimpenPosted on 2009-08-28 at 15:17:59ID: 25212001

That would be an additional step, but I have done the whole FTP, import & transfer before.

It is a group of modules. But very possible.

 

by: marellanoPosted on 2009-08-28 at 15:29:46ID: 25212044

ok great! let me contact you again next week and I can creat a new question to accept.

have a great weekend.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...