Anyone???
I have a somewhat update..
I was checking into an access book...
I can get this to work using this..
- Public Sub MergetoWord()
-
' This method creates a new document in
-
' MS Word using Automation
-
Dim rsCust As New ADODB.Recordset
-
Dim sSQL As String
-
Dim WordObj As Word.Application
-
Dim iTemp As Integer
-
-
On Error Resume Next
-
-
sSQL = "SELECT * FROM Customers " _
-
& "WHERE CustomerNumber = " _
-
& Forms!Orders![CustomerNumber]
-
-
rsCust.Open sSQL, CurrentProject.Connection
-
-
If rsCust.EOF Then
-
MsgBox "Invalid customer", vbOKOnly
-
Exit Sub
-
End If
-
-
DoCmd.Hourglass True
-
-
'Try to get a running instance of Word:
-
Set WordObj = GetObject(, "Word.Application")
-
If Err.Number <> 0 Then
-
'An error is thrown if Word is not running,
-
'so use CreateObject to start up Word:
-
Set WordObj = CreateObject("Word.Application")
-
End If
-
-
'Make sure the user can see Word:
-
WordObj.Visible = True
-
-
'Warning:
-
'Specify the correct drive and path to the
-
'file named Thanks.dotx in the line below.
-
-
WordObj.Documents.Add _
-
Template:="C:\Thanks.dotx", NewTemplate:=False
-
-
With WordObj.Selection
-
.GoTo what:=wdGoToBookmark, Name:="FullName"
-
.TypeText rsCust![ContactName]
-
-
.GoTo what:=wdGoToBookmark, Name:="CompanyName"
-
.TypeText rsCust![CompanyName]
-
-
.GoTo what:=wdGoToBookmark, Name:="Address1"
-
.TypeText rsCust![Address1]
-
-
.GoTo what:=wdGoToBookmark, Name:="Address2"
-
If IsNull(rsCust![Address2]) Then
-
.TypeText ""
-
Else
-
.TypeText rsCust![Address2]
-
End If
-
-
.GoTo what:=wdGoToBookmark, Name:="City"
-
.TypeText rsCust![City]
-
-
.GoTo what:=wdGoToBookmark, Name:="State"
-
.TypeText rsCust![State]
-
-
.GoTo what:=wdGoToBookmark, Name:="Zipcode"
-
.TypeText rsCust![Zipcode]
-
-
.GoTo what:=wdGoToBookmark, Name:="PhoneNumber"
-
.TypeText rsCust![PhoneNumber]
-
-
.GoTo what:=wdGoToBookmark, Name:="NumOrdered"
-
.TypeText Forms!Orders![Quantity]
-
-
.GoTo what:=wdGoToBookmark, Name:="ProductOrdered"
-
If Forms!Orders![Quantity] > 1 Then
-
WordObj.Selection.TypeText Forms!Orders![Item] & "s"
-
Else
-
WordObj.Selection.TypeText Forms!Orders![Item]
-
End If
-
-
.GoTo what:=wdGoToBookmark, Name:="FName"
-
-
iTemp = InStr(rsCust![ContactName], " ")
-
-
If iTemp > 0 Then
-
.TypeText Left$(rsCust![ContactName], iTemp - 1)
-
End If
-
.GoTo what:=wdGoToBookmark, Name:="LetterName"
-
.TypeText rsCust![ContactName]
-
-
DoEvents
-
WordObj.Activate
-
.MoveUp wdLine, 6
-
End With
-
-
'Set the Word Object to Nothing to free resources:
-
Set WordObj = Nothing
-
DoCmd.Hourglass False
-
-
End Sub
-
-
-
-
-
Private Sub Command12_Click()
-
-
End Sub
-
I have to open the Module and run it...
I having one heck of time trying to figure out how to make this happen with a button on the form.. I did an on click, and pasted that same code in there, and it wont do ANYTHING I made sure all the references were checked as well.
I am stumped! This is for someone else, if it the DB were for me Id be fine running the module manually, but I don't think this person will want to that.
How can I get that button to run that module???