Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-12-2018, 04:28 PM
eduzs eduzs is offline Verify if a datasource fieldname exists Windows 10 Verify if a datasource fieldname exists Office 2010 32bit
Expert
Verify if a datasource fieldname exists
 
Join Date: May 2017
Posts: 262
eduzs is on a distinguished road
Default Verify if a datasource fieldname exists

Is there a way to test if a activedocument.MailMerge.DataSource.FieldNames("My Field") exists?


Thanks
__________________
Backup your original file before doing any modification.
Reply With Quote
  #2  
Old 04-12-2018, 11:35 PM
gmayor's Avatar
gmayor gmayor is offline Verify if a datasource fieldname exists Windows 10 Verify if a datasource fieldname exists Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

You could loop through the fieldnames collection and compare with your field name

Code:
Dim iFld As Integer
Dim bFound As Boolean
    For iFld = 1 To ActiveDocument.MailMerge.DataSource.FieldNames.Count
'Debug.Print ActiveDocument.MailMerge.DataSource.FieldNames(iFld)
        If UCase(ActiveDocument.MailMerge.DataSource.FieldNames(iFld)) = "MY FIELD" Then
            MsgBox "'My Field' exists"
            bFound = True
            Exit For
        End If
    Next iFld
    If Not bFound Then MsgBox "'My Field' does not exist"
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 04-13-2018, 03:20 AM
eduzs eduzs is offline Verify if a datasource fieldname exists Windows 10 Verify if a datasource fieldname exists Office 2010 32bit
Expert
Verify if a datasource fieldname exists
 
Join Date: May 2017
Posts: 262
eduzs is on a distinguished road
Default

Thanks! Works fine!
__________________
Backup your original file before doing any modification.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Verify if a datasource fieldname exists VBA mailmerge all but last row in datasource vincenzo345 Word VBA 9 09-01-2017 05:57 AM
Verify email passwords every week? cwksr Outlook 1 08-16-2014 04:29 AM
how to get datasource element ragesz Mail Merge 1 09-29-2013 07:12 PM
Access MailMerge DataSource in VB advin Mail Merge 1 01-04-2010 01:34 AM
Changing DataSource ntfirewall Mail Merge 0 03-30-2007 06:01 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:24 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft