Hi All,
I have a general question. I'm in the process of designing a app that will
allow user to enter data for Medical forms and print the corresponding word
doc. I have about 100 forms I have to do this for. And I'm looking for ideas
that will help with my design. I'm trying to make this code as general as
possible, so that as they add/delete forms, it will make it as simple as
possible for both me and the user.
What I have so far:
I've created a xml file (still have not gotten the final design of the xml
file) that contains the the following:
<LookUp>
<ControlType>C1ComboBox</ControlType>
<DBField>PatientName</DBField>
<BookMark>PatientName</BookMark>
<ControlName>cmbPatient</ControlName>
<ColumnIndex>1</ColumnIndex> 'Optional
<Values VALUE="0" BookMark="Goal1Progress"/>'Optional
<Values VALUE="1" BookMark="Goal1Progress"/>'Optional
</LookUp>
I have a Lookup key for each field on the word document. The ControlType is
the type of control assigned to the word field. DBField would be the database
field (not used yet). ControlName is the name of the control on the data
entery form. ColumIndex is for special use. The Value keys are used with
comboboxs when using the SelectedIndex of the control to match up with the
bookmarks in the word doc. If a textbox was used, the Values key would be
replaced with one Bookmark key.
What the class does so far is to read in the xml file and based on the
values in the xml file, grabs the data off the form and inserts the values
into the corresponding bookmarks in the word doc. The class has a Print
function that does most of the work as follows:
Public Sub Print(frm as Form, ConfigFile as String, WordDoc as String )
Dim al As New clsReportElements
Dim ReportElement As New clsReportElement
Dim wdApp As Word.Application
Dim ReadXmlFile As NarcoFreedom.MTTP.clsReadXmlFile
Dim Ghost As New Control
Dim tCombo As AxTrueOleDBList80.AxTDBCombo ' C1ComboBox
Dim tTextbox As TextBox
Dim tCheckbox As CheckBox
Dim tDatePicker As AxMSComCtl2.AxDTPicker
ReadXmlFile = New NarcoFreedom.MTTP.clsReadXmlFile
al = ReadXmlFile.Run(ConfigFile)
doc = ThisApplication.Documents.Open(FileName:=WordDoc)
ThisApplication.Visible = True
ThisApplication.WindowState = Word.WdWindowState.wdWindowStateMaximize
For Each ReportElement In al
Select Case ReportElement.ControlType
Case "C1ComboBox"
Ghost = FindControl2(ReportElement.ControlName, frm)
If Not Ghost Is Nothing Then
tCombo = CType(Ghost, AxTrueOleDBList80.AxTDBCombo)
doc.FormFields.Item(ReportElement.BookMark).Result = tCombo.Text
End If
Case "Textbox"
Ghost = FindControl2(ReportElement.ControlName, frm)
If Not Ghost Is Nothing Then
tTextbox = CType(Ghost, TextBox)
doc.FormFields.Item(ReportElement.BookMark).Result = tTextbox.Text
End If
Case "CheckBox"
Ghost = FindControl2(ReportElement.ControlName, frm)
If Not Ghost Is Nothing Then
tCheckbox = CType(Ghost, CheckBox)
doc.FormFields.Item(ReportElement.BookMark).Result = tCheckbox.Checked()
End If
Case "DTPicker"
Ghost = FindControl2(ReportElement.ControlName, frm)
tDatePicker = CType(Ghost, AxMSComCtl2.AxDTPicker)
doc.FormFields.Item(ReportElement.BookMark).Result = tDatePicker.Text
End Select
Next ReportElement
doc.Activate
doc = Nothing
End Sub
What do you all think of what I have so far. With the creation of this
class, I'm hoping that it will make it easier to work with, reduce duplicate
code (by not needing all that code in every form) and make it quicker to
setup a new data enter form.
Has anyone seen any articles on doing things like this. I could use any help
on the subject. Thanks again.
Michael Lee