School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,154 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 3,959 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 Rate Topic: -----

#1 arsenalaaron  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 5
  • Joined: 23-October 08


Dream Kudos: 0

Posted 23 October 2008 - 08:30 AM

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??

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


Was This Post Helpful? 0
  • +
  • -


#2 thava  Icon User is offline

  • D.I.C Addict
  • Icon
  • Group: Expert
  • Posts: 990
  • Joined: 17-April 07


Dream Kudos: 75

Posted 24 October 2008 - 04: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

 For j = 1 To 2



use like this

 For j = 1 To doc.sentences.count


This post has been edited by thava: 24 October 2008 - 04:45 AM

Was This Post Helpful? 0
  • +
  • -

#3 arsenalaaron  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 5
  • Joined: 23-October 08


Dream Kudos: 0

Posted 24 October 2008 - 05:13 AM

View Postthava, on 24 Oct, 2008 - 05:44 AM, said:

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

 For j = 1 To 2



use like this

 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
Was This Post Helpful? 0
  • +
  • -

#4 thava  Icon User is offline

  • D.I.C Addict
  • Icon
  • Group: Expert
  • Posts: 990
  • Joined: 17-April 07


Dream Kudos: 75

Posted 24 October 2008 - 06:56 AM

where did you run this macro in word or in excel or in access
Was This Post Helpful? 0
  • +
  • -

#5 arsenalaaron  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 5
  • Joined: 23-October 08


Dream Kudos: 0

Posted 24 October 2008 - 07:58 AM

View Postthava, on 24 Oct, 2008 - 07:56 AM, said:

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



The macro is ran from Access2000
Was This Post Helpful? 0
  • +
  • -

#6 thava  Icon User is offline

  • D.I.C Addict
  • Icon
  • Group: Expert
  • Posts: 990
  • Joined: 17-April 07


Dream Kudos: 75

Posted 24 October 2008 - 06:04 PM

then did you add the microsoft word object reference
Was This Post Helpful? 0
  • +
  • -

#7 arsenalaaron  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 5
  • Joined: 23-October 08


Dream Kudos: 0

Posted 27 October 2008 - 01:58 AM

View Postthava, on 24 Oct, 2008 - 07:04 PM, said:

then did you add the microsoft word object reference



Yes all references required have been added.
Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

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

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month