Suppressing Spaces When Merge Field is Blank

User avatar
hlewton
PlatinumLounger
Posts: 3788
Joined: 24 Oct 2010, 23:39
Location: Canton, Ohio USA

Suppressing Spaces When Merge Field is Blank

Post by hlewton »

I have searched all over my records and cannot find how I used to do mail merges and suppress or eliminate spaces between fields when there was no data in certain fields. I remember it had to be exact and I created a document to copy exactly what I needed to put in the merge if I wanted the blank field to suppress a space between it and the following field. I believe the attached merge has such a code in the II_Jr field but I don’t know how to access it to view whatever code, I believe, is there. Can anyone tell me how I can view the code in the II_Jr field of the attached merge? Thanks.
5160LabelsMergeShellWithCodes.docx
You do not have the required permissions to view the files attached to this post.
Regards,
hlewton

User avatar
HansV
Administrator
Posts: 78241
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Suppressing Spaces When Merge Field is Blank

Post by HansV »

If you press Alt+F9, you will see the field codes. The field code for the II)Jr field is

{ MERGEFIELD II_Jr \f " " }

The switch \f " " means "insert a space after the II_Jr field if the next field is not empty".
See Field codes: MergeField field

S2293.png
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

User avatar
hlewton
PlatinumLounger
Posts: 3788
Joined: 24 Oct 2010, 23:39
Location: Canton, Ohio USA

Re: Suppressing Spaces When Merge Field is Blank

Post by hlewton »

HansV wrote:
25 Feb 2023, 20:10
If you press Alt+F9, you will see the field codes. The field code for the II)Jr field is

{ MERGEFIELD II_Jr \f " " }

The switch \f " " means "insert a space after the II_Jr field if the next field is not empty".
See Field codes: MergeField field


S2293.png
Thank you. I knew it was something like that but could not remember. I also used to have a template or shell document that I could use and insert the exact field I needed to use because, as I recall, the code had to be entered in a specific manner or that code would show up in place of the field. If I typed it, it would not work, but if I copied it and just changed the merge field, it worked fine. I wish I could find where I have that because I know I would not have deleted it. Maybe I can copy that code, once I see it again, and recreate the template again.
Regards,
hlewton

User avatar
HansV
Administrator
Posts: 78241
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Suppressing Spaces When Merge Field is Blank

Post by HansV »

You should not type the field brackets { }.

If you want to insert a field manually, press Ctrl+F9 to create the field brackets.
Then type the field code between the brackets.
Finally, press F9 to hide the field code and to update the result.

To insert a field from the ribbon (other than a merge field), activate the Insert tab of the ribbon.
Click Quick Parts > Field... in the Text group.

S2295.png
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

User avatar
hlewton
PlatinumLounger
Posts: 3788
Joined: 24 Oct 2010, 23:39
Location: Canton, Ohio USA

Re: Suppressing Spaces When Merge Field is Blank

Post by hlewton »

HansV wrote:
25 Feb 2023, 21:32
You should not type the field brackets { }.

If you want to insert a field manually, press Ctrl+F9 to create the field brackets.
Then type the field code between the brackets.
Finally, press F9 to hide the field code and to update the result.

To insert a field from the ribbon (other than a merge field), activate the Insert tab of the ribbon.
Click Quick Parts > Field... in the Text group.


S2295.png
First let me ask, is it Ctrl+F9 or Alt+F9 to do it manually? Then if I use whatever it is to open the brackets, once open can I insert the field by selecting Insert Field and selecting it or do I have to type the Field name, after I have typed the code, manually?
Regards,
hlewton

User avatar
HansV
Administrator
Posts: 78241
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Suppressing Spaces When Merge Field is Blank

Post by HansV »

Ctrl+F9 creates an empty new field by inserting field brackets { }. Doing so displays the field code for that field.
F9 updates the currently selected field and, if the field code is displayed, hides it.
Shift+F9 toggles the display of the field code on and off for the currently selected field.
Alt+F9 toggles the display of field codes on and off for the whole document.
Ctrl+Shift+F9 replaces the currently selected field with its result (removing the field code).

Also see Keyboard shortcuts in Word
Best wishes,
Hans

User avatar
hlewton
PlatinumLounger
Posts: 3788
Joined: 24 Oct 2010, 23:39
Location: Canton, Ohio USA

Re: Suppressing Spaces When Merge Field is Blank

Post by hlewton »

HansV wrote:
25 Feb 2023, 22:03
Ctrl+F9 creates an empty new field by inserting field brackets { }. Doing so displays the field code for that field.
F9 updates the currently selected field and, if the field code is displayed, hides it.
Shift+F9 toggles the display of the field code on and off for the currently selected field.
Alt+F9 toggles the display of field codes on and off for the whole document.
Ctrl+Shift+F9 replaces the currently selected field with its result (removing the field code).

Also see Keyboard shortcuts in Word
Thank you for that information. I believe by finagling things around a bit, I ended up with the results I needed with the other merges I was working with. I appreciate your help because without knowing how to look at those field codes using Alt+F9, I wouldn't have known I was using the correct merges I created long ago to update my current ones.
Regards,
hlewton

User avatar
Charles Kenyon
4StarLounger
Posts: 596
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Re: Suppressing Spaces When Merge Field is Blank

Post by Charles Kenyon »

Here are two references that may help: (Paul knows much more about mailmerge than I do.)

User avatar
hlewton
PlatinumLounger
Posts: 3788
Joined: 24 Oct 2010, 23:39
Location: Canton, Ohio USA

Re: Suppressing Spaces When Merge Field is Blank

Post by hlewton »

Charles Kenyon wrote:
26 Feb 2023, 02:50
Here are two references that may help: (Paul knows much more about mailmerge than I do.)
Thank you. I will check them out.
Regards,
hlewton

User avatar
hlewton
PlatinumLounger
Posts: 3788
Joined: 24 Oct 2010, 23:39
Location: Canton, Ohio USA

Re: Suppressing Spaces When Merge Field is Blank

Post by hlewton »

This is a quote from the second link, "By default, Word 2002 & later use OLE DB to get records from the data source." I remember something from years ago about having to install something like is named here. I can't remember when that went away but I have not had to install anything like that in recent years.

I still can't find my instructions I typed years ago but I must have been concerned about my memory for using code inside my mail merges. I found a couple shell merges that had all the code I have ever needed and those merges are what I used to finagle new merges, as I mentioned above. As I'm sure you guys know, from those shell documents I can create any size font and link to any database I want to. Then all I had to do was save them under a new name and save the connection to whatever database I linked them to. Luckily, no matter if I used Access or Excel files as the database, I kept all the fields consistent. Being refreshed about the use of Alt+F9 allowed me to see the shell merges I had created years ago and make use of them for my new mail merges.
Regards,
hlewton

User avatar
Charles Kenyon
4StarLounger
Posts: 596
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Re: Suppressing Spaces When Merge Field is Blank

Post by Charles Kenyon »

I'm glad you are getting it back together.
In Word jargon the shell documents are called primary merge documents.

User avatar
hlewton
PlatinumLounger
Posts: 3788
Joined: 24 Oct 2010, 23:39
Location: Canton, Ohio USA

Re: Suppressing Spaces When Merge Field is Blank

Post by hlewton »

Charles Kenyon wrote:
26 Feb 2023, 19:56
I'm glad you are getting it back together.
In Word jargon the shell documents are called primary merge documents.
Maybe I will rename them and hope to remember in the future. :grin: :cheers:
Regards,
hlewton