launch Word from Access 2007

P

P.Schuman

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.
 
P

pietlinden

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.

use late binding instead of early binding.
 
P

P.Schuman

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
 
D

Douglas J. Steele

From what I can tell, you need to do three things to use late binding in
your code

1. Remove the reference to Word (under Tools | References)

2. Remove the following line from your code:

Set wordobj = New Word.Application

(That line doesn't actually do anything, since you then set the same
variable again in the next line of code)

3. Either replace all of the references to wdGoToBookmark with the value of
that intrinsic constant (-1), or else define the constant:

Const wdGoToBookmark As Long = -1

Unrelated to Late Binding vs Early Binding, you've forgotten to declare the
variable tempvar:

Dim tempvar As String
 
A

Albert D. Kallal

Actually to lauch a copy of word you don't need any references at all.

just go

application.Followhyperlink "c:\path to word.doc"


however if you're planning to do a word merge, there and feel free to
download my sample here:

The sample I have can be found here:
http://www.members.shaw.ca/AlbertKallal/msaccess/msaccess.html

what is nice/interesting about my sample is that is specially designed to
enable ANY form with ONE LINE of code....

Thus, each time you build a new form, you can word merge enable it with
great ease.


the above sample also uses late binding.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top