PDA

View Full Version : Creating a Signature/Address block in Word



flohrstw
07-23-2012, 11:26 AM
I have a combo box (cboEmpoyee) in a userform that I would like to use to populate a signature block (txtEmployee) at the end of a letter. Currently, the combo box is populated with the names of the 5 employees that will be using the form. Ideally, the employee would select their name in the combo box and it would populate the enitre signature block on submit. The signature block is arranged as follows:

Name
Title
Organization
Phone
Fax

Any assistance would be greatly appreciated. Thanks.

gmaxey
07-23-2012, 03:34 PM
You would probably want to put all the data in a mulit-column listbox and then display only the name colomn. There are several examples of doing this here: http://gregmaxey.mvps.org/word_tip_pages/populate_userform_listbox_or_combobox.html

flohrstw
07-31-2012, 06:04 AM
I've followed the directions on the aforementioned page and have started receiving the following: "Compile Error: Only comments may appear after End Sub, End Function, or End Property." I've also noticed that on cmdSubmit the list box isn't being populated with the information from the .docx.


Form Code:
Private Sub cmdCancel_Click()
Unload Me
ActiveDocument.Close SaveChanges:=False
End Sub

Private Sub cmdSubmit_Click()
With ActiveDocument
.FormFields("Date").Result = txtDate.Value
.FormFields("To").Result = txtTo.Value
.FormFields("Facility").Result = txtFacility.Value
.FormFields("Treatment_Date").Result = txtTreatment_Date.Value
.FormFields("Name").Result = txtName.Value
.FormFields("DOB").Result = txtDOB.Value
.FormFields("Address").Result = txtAddress.Value
.FormFields("Treatment").Result = txtTreatment.Value
End With
Application.ScreenUpdating = True
Unload Me
Exit Sub

With ActiveDocument
Main.FillBMs .Bookmarks("Officer"), Me.ListBoxOfficer.Column(0)
Main.FillBMs .Bookmarks("Title"), Me.ListBoxOfficer.Column(1)
Main.FillBMs .Bookmarks("Unit"), Me.ListBoxOfficer.Column(2)
Main.FillBMs .Bookmarks("Phone"), Me.ListBoxOfficer.Column(3)
Main.FillBMs .Bookmarks("Fax"), Me.ListBoxOfficer.Column(4)
Main.FillBMs .Bookmarks("Email"), Me.ListBoxOfficer.Column(5)
End With
Me.Hide
lbl_Exit:
Exit Sub
End Sub

Option Explicit
Private Sub frmRecords_Initialize()
Dim sourcedoc As Document
Dim i As Long, j As Long, m As Long, n As Long
Dim strColWidths As String
Dim arrData() As String
Application.ScreenUpdating = False
Set sourcedoc = Documents.Open(FileName:="F:\All\Templates\sourcedoc.docx", Visible:=False)
i = sourcedoc.Tables(1).Rows.Count - 1
j = sourcedoc.Tables(1).Columns.Count
ListBoxOfficer.ColumnCount = j
ReDim arrData(i - 1, j - 1)
For n = 0 To j - 1
For m = 0 To i - 1
arrData(m, n) = Main.fcnCellText(sourcedoc.Tables(1).Cell(m + 2, n + 1))
Next m
Next n
strColWidths = "50"
For n = 2 To j
strColWidths = strColWidths + ";0"
Next n
With ListBoxOfficer
.List() = arrData
.ColumnWidths = strColWidths
End With
sourcedoc.Close SaveChanges:=wdDoNotSaveChanges
End Sub


Module Code:
Sub Document_Open()
Dim oFrm As frmRecords
Set oFrm = New frmRecords
oFrm.Show
Unload oFrm
Set oFrm = Nothing
End Sub

Document Code:
Private Sub Document_New()
frmRecords.Show
End Sub

fumei
08-01-2012, 02:25 AM
End Sub

Option Explicit
Private Sub frmRecords_Initialize()
Option Explicit must be at the top of the module. It is normally the very first line. Where it is causes the Compile error.

Where is the listbox? The code looks like it is in the document. Yes?

flohrstw
08-01-2012, 02:36 AM
The listbox is located in the userform which is intended to populate six formfields in the document on cmdSubmit. The listbox is populated by a table in the sourcedoc.docx which contains 6 columns and 12 rows including a header.

fumei
08-01-2012, 04:20 PM
Do you get any errors when you move Option Explicit into the correct location?

flohrstw
08-02-2012, 07:07 AM
That corrected the compile error, however none of the information is populating the listbox or the document on cmdSubmit.

Tinbendr
08-03-2012, 03:19 PM
Are the values showing up in the listbox?

If so, put a Break on the With ActiveDocument line, then F8 through the code making sure the values are getting to the Main.FillBMs.

flohrstw
08-03-2012, 07:06 PM
No, the values are not populating the listbox when the user form appears. Additionally, on cmdSubmit, all of the other formfields are populated in the generated document but the formfields corresponding to the listbox remain blank.

Tinbendr
08-03-2012, 07:18 PM
You'll have to backup and find out why the array is not getting moved into the listbox, or even why the array isn't being filled from the table.