Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Confused on code

Status
Not open for further replies.

rdkirb49

Technical User
Jun 24, 2004
33
US
Can any one tell me the problem with this???

Private Sub Option3_Click()

Shell "D:\archive\DUMMY_1040MFS.DOC"



End Sub



It generates the error:

Run time error '5':

Invalid call procedure or argument.



I am trying to run a mail merge document from access.



Also when I use:

Private Sub Option3_Click()

'Function MergeIt()

Dim objWord As Word.Document

Set objWord = GetObject("D:\archive\DUMMY_1040MFS.doc", "Word.Document")

' Make Word visible.

objWord.Application.Visible = True

' Set the mail merge data source as CorrBatch4Pasted.

objWord.MailMerge.OpenDataSource _

Name:="D:\archive " & _

"National Archive.mdb", _

LinkToSource:=True, _

Connection:="TABLE CorrBatch4Pasted", _

SQLStatement:="SELECT * FROM [Forms]![Batch 4 stat query]![Combo2]"

' Execute the mail merge.

objWord.MailMerge.Execute

'End Function



End Sub





My refrences would gray out when I open my switch board thus making my code non-functional and the error

Compile error:

User-defined type not defined



Reg
 
You may consider replacing this:
Shell "D:\archive\DUMMY_1040MFS.DOC"
By this:
Set Sh = CreateObject("WSCript.Shell")
Sh.Run "D:\archive\DUMMY_1040MFS.DOC"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
The reason that you're getting the Invalid Procedure error is because the intrinsic Shell function only works with executable files, those being the ones which have extensions .bat, .com, and .exe.

PHV's suggestion to use Script Shell will work because that shell is a wrapper for the ShellExecute API which opens any file by using the appropriate application associated with the file extension. .Doc files are opened with Word, .xls files are opened with Excel, and so forth.

Your user defined type error is probably caused by attempting to use the data type Word.Document object type without including a reference to the Word Object Library. In the IDE, from Tools->References, select the Microsoft Word Object Library.

Good Luck
--------------
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Thanks..... It worked!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Reg
 
Private Sub Option3_Click()
Set Sh = CreateObject("WSCript.Shell")
Sh.Run "D:\archive\DUMMY_1040MFS.DOC"
End Sub

This code is a life saver!!!!!!

Thanks to all!!!!!!!!!!

Reg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top