Replace zero length mail merge field with user input - vba

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.

Related

How can I change Access hyperlinks with VBA?

I've done some extensive research and realize this is not an easy task.
I need to change many hyperlinks in different tables from P:\Library\Folder... to I:\Folder...
I think I can change the field type to long text, find and replace, change type back to hyperlink.
Table Find/Replace dialog will work on Hyperlink field if there is no DisplayText component in hyperlink string.
In either case, an SQL UPDATE action will work, like:
CurrentDb.Execute "UPDATE table SET field = Replace([field], 'P:\Library\', 'I:\')"
It is possible to have hyperlink functionality on form and report in ReportView without Hyperlink type field. Of course this will require alternate method than hyperlink field interface to enter file path into text field - probably with VBA executing File System Object dialog. Hyperlink click will not be possible in table but since users should not interact with tables and queries, just forms and reports, this should not be an issue.

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.

Microsoft Word MacroButton - placeholder text visibility

I have a Microsoft Office 2013 Word template, in which I have some text-field elements, created by using Quick Parts -> Field -> MACROBUTTON noname [Type your text here].
If I fill only some of these fields (i.e. "[Name]", "[Address]") and I print or save as PDF, all the fields that I have not filled will display as [Insert your text here] in the printed paper or PDF. To be clear, the placeholder text must be manually removed (or replaced with the text you want).
I've readed somewhere, that you can create a macro, which will not display the placeholder text in the PFD- or printed version of the document, if there is no text written manually to that specific field (you leave it as it was). As this would be handy in cases, where you don't fill all the neccessery fields, my question is:
Q: Can this be achieved only by using Macro Button, and if not, what is needed to create text fields as described below that are not included in the printed or PDF saved version of the document?
This cannot be achieved without using actual macro code. Right now your solution contains no macro code, the fields simply function as "targets" and when the user types on the field it is deleted. Where the user does not type, the prompt remains. You'd need code to delete these fields from the document.
Given your requirement, the code would have to fire in the DocumentBeforeSave and the DocumentBeforePrint events. These events require a class and supporting code in a standard module. The basic information on how to set these up is in the Word object model language reference: https://msdn.microsoft.com/en-us/library/office/ff821218.aspx
An alternative to MacroButton fields would be to use ContentControls. But here, again, code and the same events would be required to remove/hide placeholder text.

How do I access one entry in a mail merge document?

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.