How to mail merge multiple records to one document - ms-word

I need to mail merge Access data from multiple records into 1 document. The document has standard text (form letter in the code below) at the top, followed by fields common to all the records (vendor), followed by multiple rows unique to each record (BC, Account, subaccount, amount), finally followed by more common data (payee) and text (more stuff).
Instead of putting all the record specific data together in the middle of the document, I get the first block of common data, then data from 1 record, the the rest of the common data, then the data from the 2nd record.
My setup in Word is
{ if{ mergeseq } ="1" { set var1 "" } { set var1{ mergefield key } }}
{ if { var1 } <>{ var2 } "{ if { mergeseq } <>"1" "}
Form letter
{ MERGEFIELD "Vendor_" }
" ""}
{ MERGEFIELD "BC" } { MERGEFIELD "Account" } { MERGEFIELD "SubAccount" }
{ MERGEFIELD "Amount" }
{ if { var1 } <>{ var2 } "{ if { mergeseq } <>"1" "}
more stuff
{ MERGEFIELD payee}
" ""}
{ set var2 { mergefield key }}
I'm using Office 2010.

Related

Ag-grid set column text filter to range of letters

The goal is to set a column's text filter to be a range of letters that values start with. For example in a customer name column setting the filter to be "starts with" and a range of a-m. The user will enter the two letters that define the start and end of the range (eg. "a" and "m").
Ag-grid's filter docs state that "in range" filtering is only supported for date and number data types. Looking at ag-grid's multi-filter example, multiple filters are combined with an OR condition in the filter model:
{
athlete: {
filterType: "multi",
filterModels: [
{
filterType: "text",
operator: "OR",
condition1: {
filterType: "text",
type: "startsWith",
filter: "a"
},
condition2: {
filterType: "text",
type: "startsWith",
filter: "b"
}
},
null
]
}
}
It looks like the solution is to programmatically find all letters in the range specified by the user, then include a condition for each letter in the "filterModels" array. Is there a more efficient way to do this?
A custom filter was the best solution for this scenario.
I was looking to support an optional range of letters, along with optional additional text in the filter field. Using a regular expression that matched this pattern inside the doesFilterPass method is working as expected.
Example using Vue and lodash:
doesFilterPass(params) {
// Regex matches "[A-M]", "[n-z]", "[E-p] additionaltext", etc
const nameFilterRegex = /^(?<nameStartRange>\[[a-z]{1}-[a-z]{1}\])?(?:\s+)?(?<additionalText>[a-z]+)?(?:\s+)?$/i;
const regexResult = nameFilterRegex.exec(params.data.name);
if (!isNil(regexResult)) {
const nameRange = regexResult.groups.nameStartRange;
const additionalText = regexResult.groups.additionalText;
if (!isEmpty(nameRange)) {
try {
const lastNameRegex = new RegExp(nameRange, "gi");
const matchedChar = params.data.name[0].match(lastNameRegex);
if (isEmpty(matchedChar)) {
return false;
}
} catch {
return false;
}
}
if (!isEmpty(additionalText)) {
if (!params.data.filterValue.includes(additionalText)) {
return false;
}
}
}
return true;
};

Suppress blank lines in Word when using IF Field codes

I am using the following to conditionally output text in an MS Word document:
{ IF { DOCPROPERTY manual_version } = 1 "Version 1" "" \* MERGEFORMAT }
{ IF { DOCPROPERTY manual_version } = 2 "Version 2" "" \* MERGEFORMAT }
{ IF { DOCPROPERTY manual_version } = 3 "Version 3" "" \* MERGEFORMAT }
If manual_version is set to 3, then the text "Version 3". The previous IF field codes aren't supposed to output anything but they output a blank line. How do I change that?
Your entire field code construction could be reduced to:
{DOCPROPERTY manual_version \# "'Version '0;;"}

MongoDB: How to make a query that goes through an array

I have a database filled with classes and I want to be able to find all of the classes that match the subject code and the course number provided.
course_number = ['2920', '3100', '3200', '3300', '3500', '4100', '4200', '4300', '4310', '4400', '4500']
for doc in db.all_classes.find(
{"class_schedule.subject_code": "CSCI" },
{ "class_schedule.course_number": { '$elemMatch': { course_number } } } ):
print doc

Query key with value anywhere in object hierarchy in Mongo

In Mongo how can I find all documents that have a given key and value, regardless of where that key appears in the document's key/value hierarchy?
For example the input key roID and value 5 would match both:
{
roID: '5'
}
and
{
other: {
roID: '5'
}
}
There is no built in way to do this. You might have to scan each matched document recursively to try and locate that attribute. Not recommended. You might want to think about restructuring your data or perhaps manipulating it into a more unified format so that it will be easier (and faster) to query.
If your desired key appears in a fixed number of different locations, you could use the $or operator to scan all the possibilities.
Taking your sample documents as an example, your query would look something like this:
db.data.find( { "$or": [
{ "roID": 5 },
{ "other.roID": 5 },
{ "foo.bar.roID": 5 },
{ any other possbile locations of roID },
...
] } )
If the number of documents in collection is not so large, then it can be done by this:
db.system.js.save({_id:"keyValueExisted", value: function (key, value) {
function findme(obj) {
for (var x in obj) {
var v = obj[x];
if (x == key && v == value) {
return true;
} else if (v instanceof Object) {
if (findme(v)) return true;
}
}
return false;
}
return findme(this);
}});
var param = ['roID', '5'];
db.c.find({$where: "keyValueExisted.apply(this, " + tojsononeline(param) + ");"});

Detect empty pick() from hash in KRL

I have a bunch of data in a hash and I am picking from it. Sometimes there will be data there to pick and sometimes there won't. What is the best way to know when there was something found by the pick operator and when there wasn't so I can react to that in my code?
The pick operator will take a second optional parameter that will make it so that it always returns the results in an array. This means that if something is picked, the length of the array will be greater than 0, otherwise it will be 0. You can then use that to do what you are wanting to do.
Example code/app taken from http://kynetxappaday.wordpress.com/2011/01/04/day-30-detecting-empty-pick/
ruleset a60x526 {
meta {
name "hash-pick-detect"
description <<
hash-pick-detect
>>
author "Mike Grace"
logging on
}
global {
dataHash = {
"one": {
"name": "Mike"
}, // number
"two": {
"random": 8
}, // number
"three": {
"name": "Alex"
} // number
}; // dataHash
} // global
rule detect_the_pick {
select when pageview ".*"
foreach dataHash setting (key, value)
pre {
userName = value.pick("$.name", true);
length = userName.length();
}
if (length > 0) then {
notify("Key: #{key}","Name: #{userName}<br/>Length: #{length}") with sticky = true;
}
notfired {
raise explicit event empty_pick
with pickedKey = key;
}
}
rule empty_pick_found {
select when explicit empty_pick
pre {
pickedKey = event:param("pickedKey");
results =<<
Key: #{pickedKey}<br/>
doesn't have a name associated with it to pick from
>>; //' fixing syntax highlighting
}
{
notify("An empty pick was detected",results) with sticky = true;
}
}
}