Link to home
Start Free TrialLog in
Avatar of toverholt
toverholt

asked on

File Renaming Issue

Scenario:

Directory full of Word Files that have patient dictation that is transcribed by centralized transcription.  I want to import the text into another MS SQL database.  I am accomplishing this using an Access DB intermediary, because I am most familiar with this.

My problem is that I want to rename each file once it has been imported so I don't have to re-import each time and then check for duplicates.  I wrote that routine and it is awfully slow!!!!

Here is the code that I have so far.  You will see that the rename is comm'ed out since it gives me an error.

Any help is appreciated.

Troyo
Public Function Grabdata()
Dim wdDoc As Word.Document
    Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim F
    Dim A
    
    Dim strPath As String
    
    
    Set wdDoc = Nothing
    Set wdApp = Nothing
 
    Dim strFile As String
    Dim myFullFile As String
    strPath = "X:\Shared\WPCWW\"
    strFile = Dir(strPath, vbDirectory)
    Do While strFile <> ""
    If strFile <> "." And strFile <> ".." Then
     
    'MsgBox "got this far"
     
    '************* Start Repeating Section ***************
    Set wdApp = New Word.Application
    wdApp.Visible = False
    myFullFile = strPath & strFile
    'MsgBox strPath & strFile
        
    Set wdDoc = wdApp.Documents.Open(myFullFile)
 
    
 
    DoCmd.OpenForm "frmImport", acNormal, , , acFormAdd
    
    
    Forms!frmImport![Dict] = wdDoc.Range.Text
    wdApp.Quit
    DoCmd.Close acForm, "frmImport"
    
    
    
    MsgBox "pause"
    
    
    myFullFile1 = strPath & "*" & strFile
    
    
    'Name myFullFile As myFullFile1
    
 
        'Kill myFullFile
    End If
    strFile = Dir()
    'MsgBox strFile
    
    Loop
End Function

Open in new window

Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

don't use a wild character as part of your file name

'   myFullFile1 = strPath & "*" & strFile   '<< this is the one giving errorthe
     
    myFullFile1 = strPath & "Imp_" & strFile

    'Name myFullFile As myFullFile1
Avatar of toverholt
toverholt

ASKER

Tried that...  Great idea by the way....

Gives me a Path/File Error.

then check your path ? is it correct

msgboxt myFullFile &" > " & myFullFile1
Changed to:

 myFullFile1 = "X:\Shared\WPCWW\Imported\aaa_" & strFile
   
    MsgBox myFullFile & " > " & myFullFile1
   
    Name myFullFile As myFullFile1
   


This works.  If I comment out the msgbox line, it errors.  Is this a lag issue with processing? Any way I can add a pause, so I don't have to hit enter 2000 times?

Also, I chose to move to a seperate directory as well.  I may not change the name, but just move the file.

Troyo
do you have the folder Imported created?
X:\Shared\WPCWW\Imported\

if you want to move the file, use

filecopy  sourcePath & strFile, destinationPath & strFile
Changing back to original plan of renaming


    myFullFile1 = "X:\Shared\WPCWW\aaa_" & strFile
   
    MsgBox myFullFile & " > " & myFullFile1
   
    Name myFullFile As myFullFile1
   

Works with MsgBox not without it.

Troyo
Works Most of the Time with the msgBox statement in there.  It must be a timing issue waiting for Word to close.
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for your continued help via dialogue.