UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Code to loop through directory and LoadFromText ??    
 
   
JoeOxfordCT
post Mar 19 2007, 09:30 AM
Post #1

UtterAccess Guru
Posts: 561
From: Connecticut, New England



Good Morning,

I found some code that loops through a DB and saves all the forms out as text. (I was having corruption issues)

I am now trying to write some code to loop through the directory where I saved all my forms at .txt files and do a LoadFromText. I think I have the code fine but I am getting an error message 2220; cannot open file ?
In the screenprint below you can see both the code I used to SaveAsText and the LoadFromText as well.
I am able to manually open any of these .txt files myself so why is my code locking up ??

Thanks,

J.

(IMG:http://i114.photobucket.com/albums/n244/JoeOxfordCT/LoadFromText.jpg)
Go to the top of the page
 
+
cheekybuddha
post Mar 19 2007, 10:23 AM
Post #2

UtterAccess VIP
Posts: 5,486
From: Brixton, front line



Hi Joe,

I can't tell from here, but are you passing the full path to the file or just the file name?

Perhaps try:

Application.LoadFromText acForm, R, "C:\Forms\" & strFile




hth,

d
Go to the top of the page
 
+
JoeOxfordCT
post Mar 19 2007, 10:32 AM
Post #3

UtterAccess Guru
Posts: 561
From: Connecticut, New England



Thanks d,

That solved that problem but not I can't seem to get the loop to go through all the files....it seems to just do the first .txt file over and over again.

Here's my updated code: (I commented out the LoadFromText line because I just wanted to see the loop run)
CODE
Public Function LoadFormText()

Dim strFile As String
strFile = Dir("C:\Forms\*.txt")
Dim R As String
R = Left(strFile, Len(strFile) - 4)

Do While strFile <> ""
strFile = Dir
'Application.LoadFromText acForm, R, "C:\Forms\" & strFile
MsgBox R
Loop

MsgBox "Import of Forms complete !!"
End Function
Go to the top of the page
 
+
cheekybuddha
post Mar 19 2007, 10:35 AM
Post #4

UtterAccess VIP
Posts: 5,486
From: Brixton, front line



Hi, you are not reassigning the value of R

CODE
Public Function LoadFormText()

Dim strFile As String
strFile = Dir("C:\Forms\*.txt")
Dim R As String

Do While strFile <> ""
strFile = Dir
R = Left(strFile, Len(strFile) - 4)     [color="green"]' <--- Do it here!
'Application.LoadFromText acForm, R, "C:\Forms\" & strFile
MsgBox R
Loop

MsgBox "Import of Forms complete !!"
End Function



hth,

d
Go to the top of the page
 
+
cheekybuddha
post Mar 19 2007, 10:36 AM
Post #5

UtterAccess VIP
Posts: 5,486
From: Brixton, front line



Oops! forgot the close colour tag! But I think you can see what I'm getting at.

d
Go to the top of the page
 
+
JoeOxfordCT
post Mar 19 2007, 11:21 AM
Post #6

UtterAccess Guru
Posts: 561
From: Connecticut, New England



Whoops....uh, I knew that.... (IMG:http://www.utteraccess.com/forum/style_emoticons/default/blush.gif)

Thanks very much !
I think that's got it now....
Go to the top of the page
 
+
cheekybuddha
post Mar 19 2007, 11:32 AM
Post #7

UtterAccess VIP
Posts: 5,486
From: Brixton, front line



LOL @ Joe! (IMG:http://www.utteraccess.com/forum/style_emoticons/default/grin.gif)

(IMG:http://www.utteraccess.com/forum/style_emoticons/default/thumbup.gif)

d
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 18th May 2013 - 09:47 PM