I have a screen that shows some customer data. I need to be able to click a command button and have the name, address, etc put on a MS Word 2007 document. This is my code so far.
It does not like the Dims at the top.Code:Private Sub cmdWord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdWord.Click Dim oWord As Word.Application Dim oDoc As Word.Document Dim name As String name = Trim(txtFName.Text) & " " If Trim(txtMiddle.Text) <> "" Then name = name & Trim(txtMiddle.Text) & " " End If name = name & Trim(txtLName.Text) Dim citystatezip As String citystatezip = Trim(txtCity.Text) citystatezip = citystatezip & ", " & Trim(txtState.Text) citystatezip = citystatezip & " " & Trim(TxtZip.Text) oWord = New Word.Application oDoc = oWord.Documents.Open("Z:\CRM\CRMLetter.doc") With oDoc .Bookmarks("Name").Range.Text = name .Bookmarks("Address").Range.Text = txtStreet1 .Bookmarks("citystatezip").Range.Text = citystatezip End With oWord.Visible = True oDoc = Nothing oWord = Nothing End Sub
FYI... it works in VB6




Reply With Quote