File Renaming Issue


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.

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
    DoCmd.Close acForm, "frmImport"
    MsgBox "pause"
    myFullFile1 = strPath & "*" & strFile
    'Name myFullFile As myFullFile1
        'Kill myFullFile
    End If
    strFile = Dir()
    'MsgBox strFile
End Function

Open in new window

Who is Participating?
Rey Obrero (Capricorn1)Connect With a Mentor Commented:
place this codes in a regular module

option compare database
option explicit

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)


myFullFile1 = "X:\Shared\WPCWW\aaa_" & strFile
   sleep 1000  ' just modify the value
    Name myFullFile As myFullFile1

Rey Obrero (Capricorn1)Commented:
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
toverholtAuthor Commented:
Tried that...  Great idea by the way....

Gives me a Path/File Error.

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to and use offer code ‘EXPERTS’ to get 10% off your first purchase.

Rey Obrero (Capricorn1)Commented:
then check your path ? is it correct

msgboxt myFullFile &" > " & myFullFile1
toverholtAuthor Commented:
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.

Rey Obrero (Capricorn1)Commented:
do you have the folder Imported created?

if you want to move the file, use

filecopy  sourcePath & strFile, destinationPath & strFile
toverholtAuthor Commented:
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.

toverholtAuthor Commented:
Works Most of the Time with the msgBox statement in there.  It must be a timing issue waiting for Word to close.
toverholtAuthor Commented:
Thanks for your continued help via dialogue.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.