Adding text to an existing textbox in a word document VB.Net - vb.net

My company creates a welcome packet for each new employee. In this packet, it's our job to list their name, job title, etc. We use a template for this; just a page within the word document that has textboxes for each field.
Is it possible to add info to those existing textboxes? If not, how can I re-create the page in the document with new textboxes? It's the 3rd page.
I don't know if this is even possible, but if it is please let me know.

Assume your textbox is called Textbox1. To add text to it simply write:
TextBox1.text = Textbox1.text & "String here"
Alternatively, if you want to wipe it out completely, go for
Textbox1.text = "String here"
Hope this helps!

Related

VB.NET add text to the front of text

I am trying to add text to current text that is in a textbox using a checkbox. Once the checkbox is checked, it will "add" the text to the textbox before the text already in the textbox.
example:
if the textbox said "Jake", it would say "Hello Jake" once the checkbox was checked.
EDIT: sorry for the quick question. I'm in a hurry. But the only method I could think of was concatenating and appending text. As far as I know append() adds only to the end, and concatening isn't the logical approach. I don't have a coded example because I dont even know how to approach this issue. thanks.
It's getting a thumbs down because its so simple, but not. I'm using multiple checkboxes. So one needs to be in the very front, one in the center, etc. Each checkbox injects text into the textbox a certain way. I can do this with nested if statements, but then we got a mess.
Try using this code :
if chbHello.Checked then
txtName.Text = chbHello.Text + " " + txtName.Text
Note : if the checkbox is the trigger put this code in the checkbox.
All it does is see if the checkbox was checked or not.
When its checked just concatenate the text of the textbox and the checkbox with the
checkbox first.

Create OpenFileDialog when RichTextBox selected?

In my application, a list of fields is read from a database, and then rendered in a TabControlPage. Each field has a Control of a specific type, one of which is a RichTextBox.
What I need, is when the user selects the RichTextBox, an OpenFileDialog should appear, allowing the user to select a file. The RichTextBox should then display the full path + filename(eg. C:/files/excel/thing.xlsx) in the form of a hyperlink.
Currently, you can type in the path+filename into the RichTextBox and it will automatically be made into a hyperlink.
Any suggestions, or perhaps reference material you can give me?
You can attach something like this to the Enter event on your RichTextBox:
Dim dialog As New OpenFileDialog()
Dim result As DialogResult = dialog.ShowDialog()
If result = Windows.Forms.DialogResult.OK Then
RichTextBox1.Text = dialog.FileName
End If
This is not turning it into a hyperlink for me, but it sounds like you have that part handled?
edited as per Lars' comment.

How can I save/append text from one textbox to another textbox on the same Form in VB

Basically what I'm trying to figure out how to do is save text from one textbox to another textbox on the same form. I see a lot of post on how to save or store text from one textbox to another on a different form but not any with doing that on the same form.
I'm currently working on a feature in my program that allows me to with a click fn my "LogItLater" button save the fields from the First Name, Last Name, and Phone# textboxes on my form and place them on a different textbox on my form which allows the user to add more or edit that information at later time.
I'm doing this in VB so just a simple how to would be great, this is my first time asking a question so I hope I was as specific as possible.
So my new issue is this when I add more than one statement like this
txtScrapeBox.Text = txtFirstName.Text
txtScrapeBox.Text = txtLastName.Text
txtScrapeBox.Text = txtPhone.Text
The only text that is saved is the last statement and in this case it is the txtPhone.Text, will I need a condition statement to get the first two to save as well?
Only the last assignment is retained, because you are replacing the contents with each assignment. To append (I am assuming this is a multiline TB - if it isnt, the data will come out: ZiggyWagner(800)5550195):
txtScrapeBox.Text = txtFirstName.Text & Environment.NewLine & _
txtLastName.Text & Environment.NewLine & txtPhone.Text
This presents a problem down the road - if they want to edit "LastName", how will you know which line they want to edit? You will have to save all three items to txtScrapeBox in the same order every time and fetch them back using the .Lines() property.
Another way might be to save them to a ListBox where item 0 is always first name, item 1 = LastName etc:
lbData.Items.Clear ' remove previous contents
lbData.Items.Add(txtFirstName.Text)
lbData.Items.Add(txtLastName.Text)
lbData.Items.Add(txtPhone.Text)
Get one back to edit:
txtFirstName.Text = lbData.Items(0).ToString
' or
If lbData.SelectedItems.Count > 0 Then ' check if they selected one
txtFirstName.Text = lbData.SelectedItem.ToString
End If

VB.NET / Windows Forms - Data from user input to DataReport?

I'm developing a windows forms application using VB.NET. I'm currently working on DataReport (by Microsoft, not Crystal). Everything works fine when using DataSet as DataSource. But I have a question on how am I going to put data to my DataReport from a user input? Preferably when the user is on the act of printing(clicking the print button in the ReportViewer), a Form will pop-up and ask him for input. That input I'm talking about is random names of people, and we don't have to track their names so there's no reason to put it on the database.
Here's my simple setup:
MainForm.vb (Form)
MyReportViewer (ReportViewer)
MyReport.rdlc (DataReport)
InputForm (Form)
MyInputBox (TextBox)
If it is impossible to do it on the act of printing. Maybe on the MainForm_Load event or before the generation of report can do.
I've searched the net for an hour but I'm out of luck.
I've found the answer, it's called ReportParameters.
Here's how to set it:
'Get input from user...
Dim OneParameter As String = InputBox("Enter something to display on report!", "Report Parameter")
'Prepare report parameters... The `SetParameters` requires array of `ReportParameter`...
Dim ReportParameters As New List(Of ReportParameter)
'Add the user input to `ReportParameter` array...
ReportParameters.Add(New ReportParameter("OneParameter", OneParameter, True))
'Set the `ReportParameters` of the `ReportViewer`...
FormWithReportViewer.TheReportViewer.LocalReport.SetParameters(ReportParameters)
FormWithReportViewer.Show()
FormWithReportViewer.Focus()
On the DataReport(.rdlc), we have to add a ReportParameters (Menu>Report>Report Parameters). The same name (OneParameter) should be used to avoid error. We can now use the parameter in our textbox, just put =Parameters!OneParameter.Value and we're done!
Note: We have to set the report parameters before rendering the report. If we cannot avoid that, refresh the report after adding parameters so it will be updated:
FormWithReportViewer.TheReportViewer.RefreshReport

Validating Attachment in Richtext field

I am using below code to validate the Attachment in Richtext field.
If I will not used Call source.Refresh(True)
then validation is not working, but this code is also refreshing document everytime querysave is called in buttons.
So is there any option or any other idea so that I should not user this Refresh part or entire code to validate .
If anybody have more efficient code then please share this.
If Source.Document.YesNo20(0)="Yes" Then
Call source.Refresh(True)
Dim rtitem As NotesRichTextItem
Set rtitem = source.Document.GetFirstItem( "Atchmnt20" )
NotesEmbeddedObjectArray = rtitem.EmbeddedObjects
If Isempty ( NotesEmbeddedObjectArray ) Then
Messagebox "Please enter an attachment in 20a. As you selected option Yes"
continue=False
Exit Sub
End If
End If
There's a way in LotusScript to check attachments presence even for new (not saved) documents.
Create a hidden computed field, for instance AttachmentNames with formula:
#If(#AttachmentNames!=""; "1"; "");
In LotusScript do the following:
'in new documents Form field may be empty
If doc.Form(0) = "" then
doc.Form = "YourFormAlias"
End If
'computing doc contents with the form
call doc.ComputeWithForm(false, false)
If doc.AttachmentNames(0) = "" then
MsgBox "Please attach a file",,"Attention"
Continue = False 'if you are running this code in QuerySave
Exit Sub
End If
Validating rich text fields in Lotus Notes is a bit of a dark art, but can you not just do this? (where doc is the back-end):
If(doc.HasEmbedded) Then Continue = True
There are other things you can do. Check this Lotus Developer Domain post, which covers attachments, text, embedded objects, all sorts:
http://www-10.lotus.com/ldd/nd6forum.nsf/0/8b3df10667d355768525719a00549058
Can you validate RT field with formula?
I created a hidden field below my rich text field with this Input Validation formula:
REM {Validate just when saving};
#If(!#IsDocBeingSaved; #Return(#Success); "");
REM {Should contain some file};
_filenames := #AttachmentNames;
#If(
#Elements(_filenames)=0;
#Return(#Failure("You should attach at least one file"));
#Success);
Assuming that you want to avoid the Refresh because it takes too long, here is what you may want to look at and if feasible, try to change:
Maybe you can use the "Entering" event of the RichText field in conjunction with a global variable (in the form) to skip the Refresh in your code, if the RichText field wasn't touched at all.
Are there keyword fields with "Refresh choices on document refresh" option enabled that may be safe to disable? Or even place a button that would bring up a dialog and populate the field with the selected keyword(s) - refreshing the choices won't be neccessary then, as you can always present up-to-date choices through #DbColumn/#DbLookup or NotesUIWorkspace.PickListStrings.
Is there any code (LotusScript or Formula) in "Queryrecalc" and/or "Postrecalc" form events that may be possible to optimize? For example by using a global variable (in the form) as a flag whether to execute the code in Queryrecalc/Postrecalc - set it to false just before calling Refresh in your code, then set it back to true (because this Refresh only serves to update the RichText field to the backend document).