> Good morning Arvin,
>
> I set reference to Word; I understand ADO, DAO, VBA and automation
> basically
> for excel.
>
> I read your code and I tried to apply for my database and doesn't work.
>
> When I run comes the following message: method or data not found. I think
> it
> refers any control (Me.cboAccountID). Where is this control? This is a
> column
> name in the word? When we refer ME, it means is a control in a form and
> the
> procedure should be in the form. I don't understand this. Could you
> explain?
>
> I think, the first step is creating a template.dot with a table with
> columns
> number same recordset fields number, is it right?
> Then, create book marks in the word, we must give the same names of the
> fields in the recordset, is right?
>
> I'm confused about this procedure.
>
> I'll appreciate a lot for your help.
>
> Thanks a lot
>
>
>
>
> "Arvin Meyer [MVP]" wrote:
>
>> You haven't dimmed a Word object or set a reference to it. Here's some
>> code
>> that I wrote more than 3 years ago. You'll need to set a reference to
>> Word.
>> It is well commented, but you must understand ADO coding to use it. Watch
>> out for line wrapping:
>>
>> Private Sub MergeWorkTicket()
>> On Error GoTo Err_MergeWorkTicket
>>
>> Dim WordTemplate As String
>> Dim strFullName As String
>> Dim objWord As Word.Application
>> Dim objDoc As Word.Document
>> Dim strSQL As String
>> Dim cnnConnection As ADODB.Connection
>> Dim comCommand As ADODB.Command
>> Dim rs As ADODB.Recordset
>> Dim strConnect As String
>>
>> ' ADO Recordset of the parts list on the work order
>> strSQL = "SELECT tblPartsList.PartQuantity As QTY,
>> tblPartsList.PartDescription As DESCRIPTION,
>> tblPartsList.PartSerialNumber
>> As SERIAL# "
>> strSQL = strSQL & "FROM tblWorkOrder INNER JOIN tblPartsList ON
>> tblWorkOrder.WorkOrderNumber = tblPartsList.WorkOrderNumber "
>> strSQL = strSQL & "WHERE tblPartsList.WorkOrderNumber = " &
>> Forms!frmWorkOrder!txtWorkOrderNumber
>>
>> strConnect = "Provider=SQLOLEDB;Data Source=Neptune;" & _
>> "Initial Catalog=TheDBName;" & _
>> "User ID=SA;password=Whatever"
>>
>> Set cnnConnection = New ADODB.Connection
>>
>> cnnConnection.Open strConnect
>>
>> Set comCommand = New ADODB.Command
>>
>> 'Debug.Print strSQL
>>
>> ' Assign the connection and set applicable properties
>> comCommand.ActiveConnection = cnnConnection
>> comCommand.CommandText = strSQL
>> comCommand.CommandType = adCmdText
>>
>> ' Instantiate the recordset
>> Set rs = New ADODB.Recordset
>>
>> ' Open the recordset using the command object
>> rs.Open comCommand 'rs.Open comCommand, , adOpenKeyset, adLockOptimistic
>>
>> Set objWord = CreateObject("Word.Application")
>>
>>
>> WordTemplate = Application.CurrentProject.Path & "\WorkTicket.dot"
>>
>> With objWord
>> .Visible = True
>> .Documents.Add (WordTemplate)
>> .Caption = "Work Ticket For " & Me.cboAccountID.Column(1) & ""
>>
>> ' If document is protected, Unprotect it.
>> If .ActiveDocument.ProtectionType <> wdNoProtection Then
>> .ActiveDocument.Unprotect Password:=""
>> End If
>>
>> .ActiveDocument.Bookmarks("Customer").Select
>> .Selection.Text = (CStr(Me.cboAccountID.Column(1)))
>> .ActiveDocument.Bookmarks("Address").Select
>> .Selection.Text = (CStr(Me.cboAccountID.Column(2)))
>> .ActiveDocument.Bookmarks("City").Select
>> .Selection.Text = (CStr(Me.cboAccountID.Column(3)))
>> .ActiveDocument.Bookmarks("State").Select
>> .Selection.Text = (CStr(Me.cboAccountID.Column(4)))
>> .ActiveDocument.Bookmarks("Zip").Select
>> .Selection.Text = (CStr(Me.cboAccountID.Column(5)))
>> .ActiveDocument.Bookmarks("Phone").Select
>> .Selection.Text = (CStr(Me.cboAccountID.Column(8)))
>> .ActiveDocument.Bookmarks("DateScheduled").Select
>> .Selection.Text = (Format$(Me.txtDateScheduled, "m/d/yy")) & " "
>> &
>> (Format$(Me.txtScheduledStartTime, "h:nn AM/PM"))
>> .ActiveDocument.Bookmarks("ContactName").Select
>> .Selection.Text = (CStr(txtWorkOrderContact & vbNullString))
>> .ActiveDocument.Bookmarks("Fax").Select
>> .Selection.Text = (CStr(Me.cboAccountID.Column(9)))
>> .ActiveDocument.Bookmarks("WorkOrder").Select
>> .Selection.Text = (CStr(Me.txtInvoiceNumber))
>> .ActiveDocument.Bookmarks("Problem").Select
>> .Selection.Text = (CStr(Me.txtProblemOrService & vbNullString))
>> .ActiveDocument.Bookmarks("Tech").Select
>> .Selection.Text = (CStr(Me.cboScheduledTech.Column(1) &
>> vbNullString))
>>
>> ' Debug.Print rs.RecordCount
>> If Not rs.BOF And Not rs.EOF Then
>> With CreateTableFromRst( _
>> objWord.ActiveDocument.Bookmarks("ItemDetails").Range, rs,
>> False)
>>
>> 'Apply formatting
>> .Range.Columns(1).Width = 29
>> .Range.Columns(2).Width = 337
>> .Range.Columns(3).Width = 140
>>
>> objWord.Selection.MoveDown
>> End With
>> End If
>>
>> ' Cleanup
>> Set objWord = Nothing
>>
>> End With
>>
>> Exit_MergeWorkTicket:
>> Exit Sub
>>
>> Err_MergeWorkTicket:
>> MsgBox Err.Number & ": " & Err.Description, vbInformation, "Error"
>> Resume Exit_MergeWorkTicket
>>
>> End Sub
>>
>> Function CreateTableFromRst( _
>> rngAny As Word.Range, _
>> rstAny As ADODB.Recordset, _
>> Optional fIncludeFieldNames As Boolean = False) _
>> As Word.Table
>>
>> Dim objTable As Word.Table
>> Dim fldAny As ADODB.Field
>> Dim varData As Variant
>> Dim strBookmark As String
>> Dim cField As Long
>>
>> ' Get the data from the recordset
>> varData = rstAny.GetString()
>>
>> ' Create the table
>> With rngAny
>>
>> ' Creating the basic table is easy,
>> ' just insert the tab-delimted text
>> ' add convert it to a table
>> .InsertAfter varData
>> Set objTable = .ConvertToTable()
>>
>> End With
>>
>> Set CreateTableFromRst = objTable
>> End Function
>> --
>> Arvin Meyer, MCP, MVP
>> Free MS-Access downloads:
>>
http://www.datastrat.com>>
http://www.mvps.org/access>>
http://www.accessmvp.com>>
>> "Jose Perdigao" <JosePerdigao[ at ]discussions.microsoft.com> wrote in message
>> news:A05DD86D-E406-4EDE-8BC7-639DF0BD5055[ at ]microsoft.com...
>> >I wrote the following code:
>> >
>> > Dim stDoc As String
>> >
>> > stDoc = "P5_CmtsOIM"
>> > DoCmd.OutputTo acOutputServerView, stDoc, acFormatRTF, "Cmts.doc", True
>> > Word.Range.Columns(1).Width = 50
>> > Word.Range.Columns(2).Width = 325
>> > Word.Range.Columns(3).Width = 125
>> >
>> > This code gives run time error (424) object required.
>> > How can I relate word.range for the word document that was opened by
>> > docmd.outputto?
>> >
>> > Thanks
>> > JP
>> > "Arvin Meyer [MVP]" wrote:
>> >
>> >> "Jose Perdigao" <JosePerdigao[ at ]discussions.microsoft.com> wrote in
>> >> message
>> >> news:3EB09C54-FECD-4574-850B-4BA16510EAD8[ at ]microsoft.com...
>> >> > I'm using ms access 2003 (ADP) vs SQL Server.
>> >> >
>> >> > I created a module using the method DoCmd.OutputTo to export a view
>> >> > to
>> >> > Ms
>> >> > Word.
>> >> >
>> >> > It works fine, but it needs improvement. I have two questions.
>> >> >
>> >> > 1. The columns width is not properly. I would like increase the
>> >> > column
>> >> > with.
>> >> > How can I do programmatically?
>> >>
>> >> Word.Range.Columns(1).Width = 50
>> >> Word.Range.Columns(2).Width = 325
>> >> Word.Range.Columns(3).Width = 125
>> >>
>> >> > 2. I would like create a Template with the logo and landscape format
>> >> > and
>> >> > then export to it. How can I do? Or if is possible, I would Like
>> >> > create
>> >> > the
>> >> > headers in a template and the export to it.
>> >>
>> >>
http://www.datastrat.com/Code/WordMerge.txt>> >> --
>> >> Arvin Meyer, MCP, MVP
>> >> Free MS-Access downloads:
>> >>
http://www.datastrat.com>> >>
http://www.mvps.org/access>> >>
http://www.accessmvp.com>> >>
>> >>
>> >>
>>
>>
>>