muzicman0
12-14-2006, 09:51 PM
Hi everyone,
Not sure if I should post this in the Access forum, or here, but since it seems to be a word issue, I'll start here...
The below code is actually from an access DB that was developed with the 2003 version. I recently upgraded to 2007, and now the code causes Access to crash. Wordobj is a module level word object. Basically, the design is to load a word document, scan for specific text (IE: 'Name:'", then I use extend to expand the selection to the full line (which would be something like "Name: Steve"), then get rid of the extra, so I am only left with 'Steve'. The function below actually is the code that scans the doc. (hope that made sense...):
Function txtParse(txtToFind As String) As String
Dim nAdd As Integer
nAdd = 1
If txtToFind = "Name:" Or txtToFind = "Address:" Then nAdd = 2
WordObj.Selection.ClearFormatting
With WordObj.Selection.Find
.Forward = True
.ClearFormatting
.MatchWholeWord = True
.MatchCase = False
.Wrap = wdFindContinue
.Execute FindText:=txtToFind
End With
WordObj.Selection.Extend
WordObj.Selection.Extend
txtParse = Right(WordObj.Selection, Len(WordObj.Selection) - Len(txtToFind) - nAdd)
End Function
What I have tried so far is to narrow down the crash to this line '.MatchWholeWord = True', however, just for a test, I commented out that line, and it crashed on the next line.
I have also created a macro in Word that does basically what I am looking to do, to see what code was generated, and made changes to my code. This resulted in Access locking up.
Anybody have any ideas of either a workaround or a fix? Or do you see something that I could change in my code?
Thanks for any help!
mm0
Not sure if I should post this in the Access forum, or here, but since it seems to be a word issue, I'll start here...
The below code is actually from an access DB that was developed with the 2003 version. I recently upgraded to 2007, and now the code causes Access to crash. Wordobj is a module level word object. Basically, the design is to load a word document, scan for specific text (IE: 'Name:'", then I use extend to expand the selection to the full line (which would be something like "Name: Steve"), then get rid of the extra, so I am only left with 'Steve'. The function below actually is the code that scans the doc. (hope that made sense...):
Function txtParse(txtToFind As String) As String
Dim nAdd As Integer
nAdd = 1
If txtToFind = "Name:" Or txtToFind = "Address:" Then nAdd = 2
WordObj.Selection.ClearFormatting
With WordObj.Selection.Find
.Forward = True
.ClearFormatting
.MatchWholeWord = True
.MatchCase = False
.Wrap = wdFindContinue
.Execute FindText:=txtToFind
End With
WordObj.Selection.Extend
WordObj.Selection.Extend
txtParse = Right(WordObj.Selection, Len(WordObj.Selection) - Len(txtToFind) - nAdd)
End Function
What I have tried so far is to narrow down the crash to this line '.MatchWholeWord = True', however, just for a test, I commented out that line, and it crashed on the next line.
I have also created a macro in Word that does basically what I am looking to do, to see what code was generated, and made changes to my code. This resulted in Access locking up.
Anybody have any ideas of either a workaround or a fix? Or do you see something that I could change in my code?
Thanks for any help!
mm0