VB School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB Expert!

Join 300,331 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,814 people online right now. Registration is fast and FREE... Join Now!




Runtime Error 5 when running vb code in ACCESS2000

 

Runtime Error 5 when running vb code in ACCESS2000

arsenalaaron

23 Oct, 2008 - 08:30 AM
Post #1

New D.I.C Head
*

Joined: 23 Oct, 2008
Posts: 5

Hi All

I have a module in MSACCESS2000.
The module opens all .doc's in a folder, finds some criteria (undelined word) and shows the underlined word in the Immediate window.

On the .ClearFormatting part of the code, it breaks with a runtime error 5 "Invalid procedure call or argument".

However after reviewing my code, everything looks ok.

So I tried the same code out on a different pc using the same version of Access and it worked fine. No error at all.

I have had Access re-installed on my machine but the error still occurs.

What could possibly be causing this??

CODE

Sub ProcessWordDocs()
Dim wd As Object 'Word.Application
Dim doc As Object 'Word.Document
Dim aDoc
Dim strDoc As String
Dim strProduct As String
Dim strDocName
Dim rs As DAO.Recordset
Dim rsProc As DAO.Recordset
Dim j As Long
Dim r As Range


   'On Error GoTo ProcessWordDocs_Error

    Set wd = CreateObject("Word.Application")
    wd.Visible = True
    aDoc = Dir("C:\Docs\*.doc")
    
    Do While aDoc <> ""
    
        strDoc = "C:\Docs\" & aDoc
        Set doc = wd.Documents.Open _
            (FileName:=strDoc, AddToRecentFiles:=False)
                
    For j = 1 To 2
    Set r = doc.Sentences(j)
    With r.Find
            .ClearFormatting
            .Font.Underline = 1 'wdUnderlineSingle
            .Text = ""
            .Wrap = 1 'wdFindContinue

            r.Find.Execute

            If r.Find.Found Then
            strProduct = r
            Else
            strProduct = "NONE: " & aDoc
            End If
   End With
   Next j

        
        doc.Close
        
        Debug.Print strProduct


        aDoc = Dir
    Loop
    
    Set doc = Nothing
    wd.Quit
    Set wd = Nothing
End Sub


User is offlineProfile CardPM
+Quote Post


thava

RE: Runtime Error 5 When Running Vb Code In ACCESS2000

24 Oct, 2008 - 04:44 AM
Post #2

D.I.C Addict
Group Icon

Joined: 17 Apr, 2007
Posts: 894



Thanked: 51 times
Dream Kudos: 75
My Contributions
i think problem is remove the dao.recordset in the declaration part and more over there is some error i found use my following to fix it

vb

For j = 1 To 2


use like this

vb

For j = 1 To doc.sentences.count


This post has been edited by thava: 24 Oct, 2008 - 04:45 AM
User is offlineProfile CardPM
+Quote Post

arsenalaaron

RE: Runtime Error 5 When Running Vb Code In ACCESS2000

24 Oct, 2008 - 05:13 AM
Post #3

New D.I.C Head
*

Joined: 23 Oct, 2008
Posts: 5

QUOTE(thava @ 24 Oct, 2008 - 05:44 AM) *

i think problem is remove the dao.recordset in the declaration part and more over there is some error i found use my following to fix it

vb

For j = 1 To 2


use like this

vb

For j = 1 To doc.sentences.count




Thanks for the response thava. I have removed both the dao.recordsets and removed the reference to the DAO 3.6 Object Library aswell.
But, again it still falls down on the .ClearFormatting part of my code, with the same error.

I must stress that this code works on other pc's with the same version of Access. So it has to be something to do with either my object libraries or.... on this pc.
I just need to know the possible causes for this type of error!

Thanks again
User is offlineProfile CardPM
+Quote Post

thava

RE: Runtime Error 5 When Running Vb Code In ACCESS2000

24 Oct, 2008 - 06:56 AM
Post #4

D.I.C Addict
Group Icon

Joined: 17 Apr, 2007
Posts: 894



Thanked: 51 times
Dream Kudos: 75
My Contributions
where did you run this macro in word or in excel or in access
User is offlineProfile CardPM
+Quote Post

arsenalaaron

RE: Runtime Error 5 When Running Vb Code In ACCESS2000

24 Oct, 2008 - 07:58 AM
Post #5

New D.I.C Head
*

Joined: 23 Oct, 2008
Posts: 5

QUOTE(thava @ 24 Oct, 2008 - 07:56 AM) *

where did you run this macro in word or in excel or in access



The macro is ran from Access2000
User is offlineProfile CardPM
+Quote Post

thava

RE: Runtime Error 5 When Running Vb Code In ACCESS2000

24 Oct, 2008 - 06:04 PM
Post #6

D.I.C Addict
Group Icon

Joined: 17 Apr, 2007
Posts: 894



Thanked: 51 times
Dream Kudos: 75
My Contributions
then did you add the microsoft word object reference

User is offlineProfile CardPM
+Quote Post

arsenalaaron

RE: Runtime Error 5 When Running Vb Code In ACCESS2000

27 Oct, 2008 - 01:58 AM
Post #7

New D.I.C Head
*

Joined: 23 Oct, 2008
Posts: 5

QUOTE(thava @ 24 Oct, 2008 - 07:04 PM) *

then did you add the microsoft word object reference



Yes all references required have been added.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 04:22PM

Live VB Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month