By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,558 Members | 1,673 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,558 IT Pros & Developers. It's quick & easy.

How to Dynamically set/get properties on a control

P: n/a
Hi All,
I've finally getting into .NET and have a question for you all. I'm creating
an app that needs to insert user data into a word doc. One way I thought of
doing this was to save the Word Bookmark names, Control names and db field
names in a XML file. in the app I would like to be able to load those items
into memory and use these items to fill out the word doc without the code
knowing the name of the controls or db fields. Heres an idea of what I'd like
to do:
'Load XML file
While reader.Read()
Select Case (reader.NodeType)
Case XmlNodeType.Element
'Format(reader, "Element")
If (reader.Name = "ControlName") Then
Console.WriteLine(reader.ReadElementString()) 'goes
to console for now. But will save into some structure.
End If
If (reader.Name = "BookMark") Then
Console.WriteLine(reader.ReadElementString())
End If
End Select
End While
'Open the word doc
doc = ThisApplication.Documents.Open(FileName:=VB6.GetPa th & "Note.dot")
ThisApplication.Visible = True
ThisApplication.WindowState = Word.WdWindowState.wdWindowStateMaximize
''''The following line is where I need help.
'colItems.ControlName is the Name of the control that was found in the
XML file.
'colItems.BookMark is the name od the Word Bookmark.
doc.FormFields.Item(Word Bookmark).Result = ControlGhost(Word.
ControlName).Text

If I remember correctly, I beleive I read somewhere that with reflection
you could do something like this with the controls. Is this correct? If so,
how is the best way to go about that. Is there any articles that cover this
topic. Thanks for any help that you can provide.
Michael Lee
P.S. This morning I found an article:
http://msdn.microsoft.com/library/de...usingtypes.asp
This article discusses Reflections some and is close to what I need to do,
but they talk about using Reflections on your own class. How could this be
done to get a property value from any of the controls on the form.
Thanks for any help.

Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi Everyone,
I have what I think will almost do what I need. I have found some info on
CallByName, but I have one issue left. The CallByName needs to have the
object or Control reference to work. I'm trying to write this so that I don't
have to hardcode the controls in this app. Here is an example of what I have
so far.
doc = ThisApplication.Documents.Open(FileName:=VB6.GetPa th & "Note.dot")
ThisApplication.Visible = True
ThisApplication.WindowState = Word.WdWindowState.wdWindowStateMaximize

For Each ReportElement In al
Select Case ReportElement.ControlType
Case "C1ComboBox"
doc.FormFields.Item(ReportElement.BookMark).Result =
CallByName(ControlRef, "Value", CallType.Get)
Case "Textbox"
doc.FormFields.Item(ReportElement.BookMark).Result =
CallByName(ControlRef, "Text", CallType.Get)
Case "CheckBox"
doc.FormFields.Item(ReportElement.BookMark).Result =
CallByName(ControlRef, "Value", CallType.Get)
Case "DTPicker"
doc.FormFields.Item(ReportElement.BookMark).Result =
CallByName(ControlRef, "Text", CallType.Get)
End Select
Next ReportElement

doc.PrintOut()
doc.Close(Word.WdSaveOptions.wdDoNotSaveChanges)

What is the best way to get the reference to the control. I'm new to VB.NET,
but have used VB6 for years, so please bear with me, lol. Thanks for any help.
Michael

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.