this is from a biz friend - coding an app in Access 2007
I'll get the snipet of code from him later tonight...
---
Hey - I am starting to launch Word 2007 from Access 2007.
To do it I must go to VB references and check Word 12.0 object library.
It then works and I can launch Word 2007.
But I worry that it will blow up on every other computer
since they won't have this checked.
here's the snipet of code..... (I'm not a VBA person - so be gentle)
it gets invoked via a button on an invoicing page within the system
------------------
what is "late binding" vs "early binding" - with respect to launching Word ?
Private Sub Command211_Click()
On Error Resume Next
Dim txt As String
Dim wordobj As Object
Set wordobj = New Word.Application
Set wordobj = GetObject(, "word.application")
If Err.number <> 0 Then
'An error is thrown if word is not running
' So use create object to start word
'Set wordobj = CreateObject("word.application")
End If
wordobj.Documents.Add _
Template:="c:\MSG-Invoice-Template.dotx", Newtemplate:=False
'Make sure the user can see word
'
Dim rstInvoice As Recordset
Dim dbsMsg As Database
Set dbsMsg = CurrentDb()
Set rstInvoice = dbsMsg.OpenRecordset("dbInvoiceLog1")
tempvar = "InvoiceNumber='" & "Asseeed" & "' "
rstInvoice.FindFirst tempvar
If rstInvoice.NoMatch Then
MsgBox "Not FOund"
End If
wordobj.Visible = True
With wordobj.Selection
..Goto what:=wdGoToBookmark, Name:="ProjectNumber"
txt = rstInvoice!ProjectNumber
..TypeText txt
..Goto what:=wdGoToBookmark, Name:="InvoiceNumber"
txt = rstInvoice!InvoiceNumber
..TypeText txt
..Goto what:=wdGoToBookmark, Name:="Invoicedate"
txt = Format(rstInvoice!InvoiceDate, "mmmm d, yyyy")
..TypeText txt
..Goto what:=wdGoToBookmark, Name:="BillingName"
..TypeText "Mr. Homer Simpson"
..Goto what:=wdGoToBookmark, Name:="BillingCompany"
..TypeText "Burns Technologies"
..Goto what:=wdGoToBookmark, Name:="BillingStreetAddress1"
..TypeText "123 Elm"
..Goto what:=wdGoToBookmark, Name:="BillingCity"
..TypeText "Chicago"
..Goto what:=wdGoToBookmark, Name:="BillingState"
..TypeText "IL"
..Goto what:=wdGoToBookmark, Name:="BillingZip"
..TypeText "60606"
txt = rstInvoice!InvoiceDescription
..Goto what:=wdGoToBookmark, Name:="InvoiceDescription"
..TypeText txt
txt = Format(rstInvoice!Fees, "$##,###.99")
..Goto what:=wdGoToBookmark, Name:="Fees"
..TypeText txt
txt = rstInvoice!Expenses
..Goto what:=wdGoToBookmark, Name:="Expenses"
..TypeText txt
txt = rstInvoice!InvoiceAmount
..Goto what:=wdGoToBookmark, Name:="InvoiceAmount"
..TypeText txt
DoEvents
wordobj.Activate
End With
Set wordobj = Nothing
End Sub