Invalid Outside Procedure! Need Help!

Associate
Joined
29 Oct 2002
Posts
307
Location
Land Of Pork Pies!
Im currently tinkering with a new database for managing our calls and quotations and I was wondering if you could help me out.

Im trying to prevent doubling the workload as we currently type an enquiry out and then we type a quotation I want to type out an enquiry and then click a button to copy all the information into a word template.

I have been following this online procedure;

http://blogs.techrepublic.com.com/msoffice/?p=164

The code I have used is below and I have uploaded the file aswell so that if anyone can help me out and take alook?

http://files-upload.com/files/495888/New Database.zip

Im currently receiving the following error!

"The expression On Click you entered as the event property setting produced the following error: Invalid outside procedure"

This is my code;

Private Sub cmdPrint_Click()
'Print customer slip for current customer.
Dim appWord As Word.Application
Dim doc As Word.Document
'Avoid error 429, when Word isn’t open.
On Error Resume Next
Err.Clear
'Set appWord object variable to running instance of Word.
Set appWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then
'If Word isn’t open, create a new instance of Word.
Set appWord = New Word.Application
End If
Set doc = appWord.Documents.Open("C:\Documents and Settings\Administrator\Desktop\New Database\quotations.dot", , True)
With doc
.FormFields("fldCompanyName").Result = Me!CompanyName
.FormFields("fldReference").Result = Me!Reference
.FormFields("fldAddress1").Result = Me!Address1
.FormFields("fldPostalTown").Result = Me!PostalTown
.FormFields("fldCounty").Result = Me!COUNTY
.FormFields("fldPostCode").Result = Me!PostCode
.FormFields("fldContactName").Result = Me!ContactName
.FormFields("fldProjectTitle").Result = Me!ProjectTitle
.FormFields("fldDealtWithBy").Result = Me!DealtWithBy
.Visible = True
.Activate
End With
Set doc = Nothing
Set appWord = Nothing
Exit Sub

errHandler:
MsgBox Err.Number & ": " & Err.Description

End Sub

If anyone could help me it would be greatly appreciated
 
View your code, you have two random 'End Sub' at the top of your code delete them. See below: -

Option Compare Database

End Sub

End Sub


Although your code still doesn't run. Here is an example of my code (a snippet) if you want to use it. In my ID.doc (template) I created bookmarks so the code knows where to put the info.

Dim MyWord As Object
Set MyWord = CreateObject("Word.Application")

Dim PathDocu As String

With MyWord
.Documents.Open (CurrentProject.Path & "\ID.doc")


If Me.txtFirstName <> "" Then
MyWord.ActiveDocument.Bookmarks("Firstname").Range.Text = Me.txtFirstName
End If

If Me.txtSurname <> "" Then
MyWord.ActiveDocument.Bookmarks("Surname").Range.Text = Me.txtSurname
End If

.Visible = True
End With

Set MyWord = Nothing
End Sub
 
Im a bit of a novice with VBA, anyone got any ideas why my script wont work? or has anyone got the time to download my file and have a play with it? it will be greatly appreciated!
 
Back
Top Bottom