How do I access one entry in a mail merge document? - vb.net

I have set up a mail merged XtraReport, and it works fine. Now I want to access one entry in that mail merged report. By entry I mean the text associated with one row in the dataset, i.e. with the values filled in instead of having the square brackets with the field names.
So if have an XRRichText in my report with the text "Hi [name]" I want access to the XRRichText object with the RTF value "Hi Sandy"
Edit: Added information in example, added VB.net tag

Try the GetCurrentColumnValue method described here.

Related

Replace zero length mail merge field with user input

I have a MS Word template where I have certain mail-merge fields and one of those fields in the source doucment is sometimes empty. I am using below IF condition and taking user's input for the date field but I cannot update the source mail merge document with this information.
If Len(ActiveDocument.MailMerge.DataSource.DataFields("startDate").Value) < 1 Then
InputStartDate = Format(InputBox("Enter Commenced date ..."), "mm/dd/yyyy")
ActiveDocument.MailMerge.DataSource.DataFields("startDate").Value = InputStartDate
End If
I get an error here that says mail merge source doucment field connot be edited or is locked, something like this.
Is there any way through which I could either update the source field and through application refresh method, I populate that mail merge field with this user input date?
Alternatively I could otherwise add a few lines of code to perform following steps:
1- Save this document (using Saveas2 method) as ".docx" by converting it from ".docm"
2- Break the mail merge connection through VBA code
3- Select all mail merge fields and using Sendkeys "CTRL+SHIFT+F9" covert all of them to normal strings.
4- Make that particular mail-merge field a Bookmark field and then finally update that bookmark field with the user input.
This sounds like a longer route of getting a simple empty mail merge field issue fixed but this is so far all that I could think of. If you have any better suggestion, please let me know.
Instead of vba, do this with fields. Then it becomes part of the Mail Merge.
{ IF { MergeField startDate } > 0 "{MergeField starttDate }" "{ FillIn "What is the Start Date?" }" }
This will trigger the Fill-In field unless there is content in the startDate field for the record.
Here is documentation on the Fill-In Field.
Here is documentation on the IF Field.
Here is my tutorial on the Ask and Fill-In Fields.
Here is my article on Dealing With Fields in Microsoft Word.
Here is Word MVP Paul Edstein's Tutorial on Mailmerge Tips and Tricks.

MS Word VB make check box control invisible when merge field is null

I have a query that pulls information I need to use in a mail merge document to email to people for verification of information. There are 8 fields they need to verify, preferably with a check box control, but some of the fields contain no information. I would like to make the check box next to merge fields that contain no data (or whatever I may need to write into the query to make this work) invisible. If this could be accomplished easier in a completely different way, that would be fine too. Thank you.
As Cindy said, this kind of thing is handled via field coding in the mailmerge main document, not via VB code. Such a field might be coded as:
{IF{MERGEFIELD myCheck}<> "" "[ ]"}
or:
{IF«myCheck»<> "" "[ ]"}
where 'myCheck' is the field name and '[ ]' is the checkbox content control.
Note: The field brace pairs (i.e. '{ }') for the above examples are all created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac or, if you’re using a laptop, you might need to use Ctrl-Fn-F9); you can't simply type them or copy & paste them from this message. Nor is it practical to add them via any of the standard Word dialogues. Likewise, the chevrons (i.e. '« »') are part of the actual mergefields - which you can insert from the 'Insert Merge Field' dropdown (i.e. you can't type or copy & paste them from this message, either). The spaces represented in the field constructions are all required.

MS Access | How to get content from mail body to table?

I am working on a project where I need to get ms access table/data from mail body and execute some command in SAP. I can manage SAP part but issue is that how to get information from mail body. i tried linking my mailbox in access but it shows me all mail body text but i need some specified contents only. example
Hello,
Please supplement budget
WBS Amt
N.10002077.001 1
from above what i need is just "N.10002077.001" and "1" ,but how to get that information only in table is the issue?
Further, what I will get in my mail will be table with 2 column but access imports it as a simple text.
It is impossible to give a definite answer to your question because it is too vague but it is possible to get you started.
Have a look at this answer of mine: https://stackoverflow.com/a/12146315/973283. The question is not relevant other than the OP did not understand that showing screenshots told us little about what the body looked like to a VBA macro. The answer includes a macro that copies selected properties from every email in Inbox to an Excel worksheet. This will allow you to see what an email’s body looks like to a VBA macro.
How will you identify the emails from which you wish to extract data? The two simple choices are:
Look at every email in a folder and identify the interesting one by examining the subject, sender or some other property.
Select the interesting emails then run a macro which uses ActiveExplorer to access the selected emails.
The answer referenced above demonstrates technique 1. There are lots of answers demonstrating technique 2 but I can add an example macro if necessary.
An email typically has an Html body and a text body. If an email has an Html body, that is the one shown to the user. A macro can access either or both. Your screen shot looks like a text body although appearances can be deceptive. If it is a text body, the email does not have an Html body.
If it is a text body, the layout of the body is probably something like:
Hello,{cr}{lf}
Please supplement budget{cr}{lf}
WBS{tab}{tab}{tab}{tab}{tab}Amt{cr}{lf}
N.10002077.001{tab}{tab}1{cr}{lf}
This assumes, the sender has used variable numbers of tabs to line up the columns.
You could use Split on vbCr & vbLf to convert the string body into an array of strings with one line per array entry. Discard lines up to and including the line starting “WBS” then process each line down to any signature. Split each line on vbTab and expect to find two entries with values with the rest blank.
See how far you can get with the above hints then clarify your answer if you need more information.

Extracting table data from Outlook email body

I am getting Outlook email, were the Body contains a Table consisting of several string Labels and associated string Text. I want to extract three Values associated with the respective Label. The first two searchs are one column right of the Label and the last one is one row below the Label.
I tried InStr() which works great for retrieving to the right of the Label, but it doesn't seem to work for the Value that is one cell below the Label.
Can I use MoveRight and MoveDown from Excel/Work inside the Outlook VBA or use "Range(Rng.Offset(0, 1).Address).Value" and "Range(Rng.Offset(1, 0).Address).Value" to select the Value to the right and below in Outlook VBA.
Key point here is that it is a structured table in the email body.
i have one email with a table that happens to be nested inside another table
that is why Tables(1).Tables(1) is used
the following code is for exploring the table.
first line highlights the cell in the table, so that you can check if you are referring the correct cell
the second and third lines shows how to get the value of a table cell
do not try to examine any range object in the watch window or the locals window. it causes outlook to crash. (no idea why)
if you want to explore any attributes of the range object then copy the email body to msWord. it does not crash when examining the range object
i could not find anything that refers to column headers
Sub aaaaa()
Application.Inspectors(1).WordEditor.Tables(1).Tables(1).Rows(1).Cells(1).Select
stop
Debug.Print Application.Inspectors(1).WordEditor.Tables(1).Tables(2).Rows(3).Cells(4).Range.Text
Debug.Print ActiveDocument.Tables(1).Tables(1).Cell(1, 1).Range.Text
End Sub

Printing custom ranges or items in Word 2010 using VBA

I am fairly new to VBA (Word 2010) and I'm unsure if something I'd like to do is even possible in the way that I want to do it, or if I need to investigate completely different avenues. I want to be able to print ranges (or items) that are not currently enumerated as part of either wdPrintOutRange or wdPrintOutItem. Is it possible to define a member of a wd enumeration?
As an example, I'd like to be able to print comments by a particular user. wdPrintComments is a member of the wdPrintOutItem enumeration, but, I only want comments that have an Initial value of JQC. Can I define a wdPrintCommentsJQC constant? My code is reasonably simple; I have a userform that lets the user pick some settings (comments by user, endnotes only, etc.) and a Run button whose Click event should generate a PrintOut method with the proper attributes. Am I on the wrong track?
(If it matters, the Initial values will be known to me as I write the code. I have a discrete list.)
No, it's not possible to add a constant to a predefined enumeration type.
However, one possible way to do this would be to build a string of page numbers which contain the items you wish to print, open the print dialog in the "dialogs" collection, and set it to print a specified range, andinsert the string containing the list of pages (separate them with commas). Finally, execute the .show method of the print dialog to show it to the user and give them the opportunity to set any other items and click the "ok" button. I've done something very similar when I needed to print a specific chapter of a long document, and so I had to specify the "from" section and page and the "to" section and page for the user. Below I just show how to specify a list of pages instead of the ".form" and "to" I was using:
With Dialogs(wdDialogFilePrint)
.Range = wdPrintRangeOfPages
.Pages = "3,5,7-11"
.show
end with
I'm not sure how you want to print the comments (or other elements), but you could create another document and insert what you want to print on this document.
According to what you want, you could insert them as they were (comments, footnotes, etc) or as plain text, or any other format.