Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Michael Koerner Michael Koerner is offline
external usenet poster
 
Posts: 41
Default Selecting Only One Record In A Merge

I sometimes only need to print one envelope from my mail merge list. Thanks
to Peter Jamieson who a wrote who a while ago wrote the following macro for
me which allows me to select a starting letter for the merge. I was
wondering if the macro (I have a hard time spelling macro) could be edited
so that if I inserted a telephone number only that record would pop up in
the envelope.

Sub OneMergePerInitialLetterAskStart()
' error trapping to be added
Dim bDone As Boolean
Dim iLetter As Integer
Dim objMMMD As Word.Document
Dim strColumnName As String
Dim strSheetName As String
Dim strStartLetter As String
bDone = False
Do
strStartLetter = InputBox("Enter the starting letter," & _
" or blank to quit", "Starting letter", "a")
strStartLetter = UCase(Trim(strStartLetter))
If Len(strStartLetter) = 0 Then
bDone = True
Else
If Len(strStartLetter) 1 Then
MsgBox "Enter a single letter" & _
" (from A to Z or a to z)," & _
" or blank to quit", vbOKOnly
Else
If strStartLetter "A" _
Or strStartLetter "Z" Then
MsgBox "Enter a (single) letter" & _
" from A to Z or a to z," & _
" or blank to quit", vbOKOnly
Else
bDone = True
End If
End If
End If
Loop Until bDone

If strStartLetter "" Then
' Set this to the name of the worksheet or to the range name
strSheetName = "Nominal Roll$"
' Set this to the exact name of the column containing the name
' (upper/lower case is probably significant
strColumnName = "LastName"

Set objMMMD = ActiveDocument
With objMMMD
For iLetter = Asc(strStartLetter) To Asc("Z")
.MailMerge.DataSource.QueryString = _
" SELECT * FROM [" & strSheetName & "]" & _
" WHERE ucase(" & strColumnName & ") like '" & _
Chr(iLetter) & "%'"
With .MailMerge
' remove or change this as necessary
.Destination = wdSendToNewDocument
On Error GoTo norecords
.Execute Pause:=False
End With
If MsgBox("Completed Letter " & Chr(iLetter) & _
". Do the next letter?", vbOKCancel) = vbCancel Then
Exit For
End If
norecords:
If Err.Number = 5631 Then
' Assume it is because there were no records for this letter
' Not necessarily true - could be just a badly formed query
Err.Clear
On Error GoTo 0
Resume atloop
Else
' just stop
On Error GoTo 0
End If
atloop:
Next
End With
Set objMMMD = Nothing
End If
End Sub


--

Regards
Michael Koerner



  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Selecting Only One Record In A Merge

Can the phone number only appear in one column in your data source, or
could it be in several? Do your numbers have non-numeric characters,
e.g. extension numbers introduced with "x", international "+" at the
beginning of the number, spaces, etc.?

Peter Jamieson

http://tips.pjmsn.me.uk
Visit Londinium at http://www.ralphwatson.tv

Michael Koerner wrote:
I sometimes only need to print one envelope from my mail merge list. Thanks
to Peter Jamieson who a wrote who a while ago wrote the following macro for
me which allows me to select a starting letter for the merge. I was
wondering if the macro (I have a hard time spelling macro) could be edited
so that if I inserted a telephone number only that record would pop up in
the envelope.

Sub OneMergePerInitialLetterAskStart()
' error trapping to be added
Dim bDone As Boolean
Dim iLetter As Integer
Dim objMMMD As Word.Document
Dim strColumnName As String
Dim strSheetName As String
Dim strStartLetter As String
bDone = False
Do
strStartLetter = InputBox("Enter the starting letter," & _
" or blank to quit", "Starting letter", "a")
strStartLetter = UCase(Trim(strStartLetter))
If Len(strStartLetter) = 0 Then
bDone = True
Else
If Len(strStartLetter) 1 Then
MsgBox "Enter a single letter" & _
" (from A to Z or a to z)," & _
" or blank to quit", vbOKOnly
Else
If strStartLetter "A" _
Or strStartLetter "Z" Then
MsgBox "Enter a (single) letter" & _
" from A to Z or a to z," & _
" or blank to quit", vbOKOnly
Else
bDone = True
End If
End If
End If
Loop Until bDone

If strStartLetter "" Then
' Set this to the name of the worksheet or to the range name
strSheetName = "Nominal Roll$"
' Set this to the exact name of the column containing the name
' (upper/lower case is probably significant
strColumnName = "LastName"

Set objMMMD = ActiveDocument
With objMMMD
For iLetter = Asc(strStartLetter) To Asc("Z")
.MailMerge.DataSource.QueryString = _
" SELECT * FROM [" & strSheetName & "]" & _
" WHERE ucase(" & strColumnName & ") like '" & _
Chr(iLetter) & "%'"
With .MailMerge
' remove or change this as necessary
.Destination = wdSendToNewDocument
On Error GoTo norecords
.Execute Pause:=False
End With
If MsgBox("Completed Letter " & Chr(iLetter) & _
". Do the next letter?", vbOKCancel) = vbCancel Then
Exit For
End If
norecords:
If Err.Number = 5631 Then
' Assume it is because there were no records for this letter
' Not necessarily true - could be just a badly formed query
Err.Clear
On Error GoTo 0
Resume atloop
Else
' just stop
On Error GoTo 0
End If
atloop:
Next
End With
Set objMMMD = Nothing
End If
End Sub


  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Michael Koerner Michael Koerner is offline
external usenet poster
 
Posts: 41
Default Selecting Only One Record In A Merge

Peter;

The phone number is only in one data source which is in this case is Excel
Col " O" with a header row called PhoneNumber and appear as xxx-xxx-xxxx

--

Regards
Michael Koerner


"Peter Jamieson" wrote in message
...
Can the phone number only appear in one column in your data source, or
could it be in several? Do your numbers have non-numeric characters,
e.g. extension numbers introduced with "x", international "+" at the
beginning of the number, spaces, etc.?

Peter Jamieson

http://tips.pjmsn.me.uk
Visit Londinium at http://www.ralphwatson.tv

Michael Koerner wrote:
I sometimes only need to print one envelope from my mail merge list.
Thanks
to Peter Jamieson who a wrote who a while ago wrote the following macro
for
me which allows me to select a starting letter for the merge. I was
wondering if the macro (I have a hard time spelling macro) could be edited
so that if I inserted a telephone number only that record would pop up in
the envelope.

Sub OneMergePerInitialLetterAskStart()
' error trapping to be added
Dim bDone As Boolean
Dim iLetter As Integer
Dim objMMMD As Word.Document
Dim strColumnName As String
Dim strSheetName As String
Dim strStartLetter As String
bDone = False
Do
strStartLetter = InputBox("Enter the starting letter," & _
" or blank to quit", "Starting letter", "a")
strStartLetter = UCase(Trim(strStartLetter))
If Len(strStartLetter) = 0 Then
bDone = True
Else
If Len(strStartLetter) 1 Then
MsgBox "Enter a single letter" & _
" (from A to Z or a to z)," & _
" or blank to quit", vbOKOnly
Else
If strStartLetter "A" _
Or strStartLetter "Z" Then
MsgBox "Enter a (single) letter" & _
" from A to Z or a to z," & _
" or blank to quit", vbOKOnly
Else
bDone = True
End If
End If
End If
Loop Until bDone

If strStartLetter "" Then
' Set this to the name of the worksheet or to the range name
strSheetName = "Nominal Roll$"
' Set this to the exact name of the column containing the name
' (upper/lower case is probably significant
strColumnName = "LastName"

Set objMMMD = ActiveDocument
With objMMMD
For iLetter = Asc(strStartLetter) To Asc("Z")
.MailMerge.DataSource.QueryString = _
" SELECT * FROM [" & strSheetName & "]" & _
" WHERE ucase(" & strColumnName & ") like '" & _
Chr(iLetter) & "%'"
With .MailMerge
' remove or change this as necessary
.Destination = wdSendToNewDocument
On Error GoTo norecords
.Execute Pause:=False
End With
If MsgBox("Completed Letter " & Chr(iLetter) & _
". Do the next letter?", vbOKCancel) = vbCancel Then
Exit For
End If
norecords:
If Err.Number = 5631 Then
' Assume it is because there were no records for this letter
' Not necessarily true - could be just a badly formed query
Err.Clear
On Error GoTo 0
Resume atloop
Else
' just stop
On Error GoTo 0
End If
atloop:
Next
End With
Set objMMMD = Nothing
End If
End Sub




  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Michael Koerner Michael Koerner is offline
external usenet poster
 
Posts: 41
Default Selecting Only One Record In A Merge

Peter;

I could introduce a 5 digit (xxxxx) record number in Col A if that would
make things easier. That way it would cover any international addresses that
may pop up in the future.

--

Regards
Michael Koerner


"Peter Jamieson" wrote in message
...
Can the phone number only appear in one column in your data source, or
could it be in several? Do your numbers have non-numeric characters,
e.g. extension numbers introduced with "x", international "+" at the
beginning of the number, spaces, etc.?

Peter Jamieson

http://tips.pjmsn.me.uk
Visit Londinium at http://www.ralphwatson.tv

Michael Koerner wrote:
I sometimes only need to print one envelope from my mail merge list.
Thanks
to Peter Jamieson who a wrote who a while ago wrote the following macro
for
me which allows me to select a starting letter for the merge. I was
wondering if the macro (I have a hard time spelling macro) could be edited
so that if I inserted a telephone number only that record would pop up in
the envelope.

Sub OneMergePerInitialLetterAskStart()
' error trapping to be added
Dim bDone As Boolean
Dim iLetter As Integer
Dim objMMMD As Word.Document
Dim strColumnName As String
Dim strSheetName As String
Dim strStartLetter As String
bDone = False
Do
strStartLetter = InputBox("Enter the starting letter," & _
" or blank to quit", "Starting letter", "a")
strStartLetter = UCase(Trim(strStartLetter))
If Len(strStartLetter) = 0 Then
bDone = True
Else
If Len(strStartLetter) 1 Then
MsgBox "Enter a single letter" & _
" (from A to Z or a to z)," & _
" or blank to quit", vbOKOnly
Else
If strStartLetter "A" _
Or strStartLetter "Z" Then
MsgBox "Enter a (single) letter" & _
" from A to Z or a to z," & _
" or blank to quit", vbOKOnly
Else
bDone = True
End If
End If
End If
Loop Until bDone

If strStartLetter "" Then
' Set this to the name of the worksheet or to the range name
strSheetName = "Nominal Roll$"
' Set this to the exact name of the column containing the name
' (upper/lower case is probably significant
strColumnName = "LastName"

Set objMMMD = ActiveDocument
With objMMMD
For iLetter = Asc(strStartLetter) To Asc("Z")
.MailMerge.DataSource.QueryString = _
" SELECT * FROM [" & strSheetName & "]" & _
" WHERE ucase(" & strColumnName & ") like '" & _
Chr(iLetter) & "%'"
With .MailMerge
' remove or change this as necessary
.Destination = wdSendToNewDocument
On Error GoTo norecords
.Execute Pause:=False
End With
If MsgBox("Completed Letter " & Chr(iLetter) & _
". Do the next letter?", vbOKCancel) = vbCancel Then
Exit For
End If
norecords:
If Err.Number = 5631 Then
' Assume it is because there were no records for this letter
' Not necessarily true - could be just a badly formed query
Err.Clear
On Error GoTo 0
Resume atloop
Else
' just stop
On Error GoTo 0
End If
atloop:
Next
End With
Set objMMMD = Nothing
End If
End Sub




  #5   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Michael Koerner Michael Koerner is offline
external usenet poster
 
Posts: 41
Default Selecting Only One Record In A Merge

Plus a 5 digit number is easier to insert than a 10 digit telephone number
g

--

Regards
Michael Koerner


"Michael Koerner" wrote in message
...
Peter;

I could introduce a 5 digit (xxxxx) record number in Col A if that would
make things easier. That way it would cover any international addresses that
may pop up in the future.

--

Regards
Michael Koerner


"Peter Jamieson" wrote in message
...
Can the phone number only appear in one column in your data source, or
could it be in several? Do your numbers have non-numeric characters,
e.g. extension numbers introduced with "x", international "+" at the
beginning of the number, spaces, etc.?

Peter Jamieson

http://tips.pjmsn.me.uk
Visit Londinium at http://www.ralphwatson.tv

Michael Koerner wrote:
I sometimes only need to print one envelope from my mail merge list.
Thanks
to Peter Jamieson who a wrote who a while ago wrote the following macro
for
me which allows me to select a starting letter for the merge. I was
wondering if the macro (I have a hard time spelling macro) could be edited
so that if I inserted a telephone number only that record would pop up in
the envelope.

Sub OneMergePerInitialLetterAskStart()
' error trapping to be added
Dim bDone As Boolean
Dim iLetter As Integer
Dim objMMMD As Word.Document
Dim strColumnName As String
Dim strSheetName As String
Dim strStartLetter As String
bDone = False
Do
strStartLetter = InputBox("Enter the starting letter," & _
" or blank to quit", "Starting letter", "a")
strStartLetter = UCase(Trim(strStartLetter))
If Len(strStartLetter) = 0 Then
bDone = True
Else
If Len(strStartLetter) 1 Then
MsgBox "Enter a single letter" & _
" (from A to Z or a to z)," & _
" or blank to quit", vbOKOnly
Else
If strStartLetter "A" _
Or strStartLetter "Z" Then
MsgBox "Enter a (single) letter" & _
" from A to Z or a to z," & _
" or blank to quit", vbOKOnly
Else
bDone = True
End If
End If
End If
Loop Until bDone

If strStartLetter "" Then
' Set this to the name of the worksheet or to the range name
strSheetName = "Nominal Roll$"
' Set this to the exact name of the column containing the name
' (upper/lower case is probably significant
strColumnName = "LastName"

Set objMMMD = ActiveDocument
With objMMMD
For iLetter = Asc(strStartLetter) To Asc("Z")
.MailMerge.DataSource.QueryString = _
" SELECT * FROM [" & strSheetName & "]" & _
" WHERE ucase(" & strColumnName & ") like '" & _
Chr(iLetter) & "%'"
With .MailMerge
' remove or change this as necessary
.Destination = wdSendToNewDocument
On Error GoTo norecords
.Execute Pause:=False
End With
If MsgBox("Completed Letter " & Chr(iLetter) & _
". Do the next letter?", vbOKCancel) = vbCancel Then
Exit For
End If
norecords:
If Err.Number = 5631 Then
' Assume it is because there were no records for this letter
' Not necessarily true - could be just a badly formed query
Err.Clear
On Error GoTo 0
Resume atloop
Else
' just stop
On Error GoTo 0
End If
atloop:
Next
End With
Set objMMMD = Nothing
End If
End Sub







  #6   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Selecting Only One Record In A Merge

See how you get on with this (it's a completely separate process from
the last one)

FWIW I try to keep the amount of "coding to order" I do to an absolute
minimum. This is more than I've done for some time.

Sub SelectPhoneNumberAndMerge()
' error trapping to be added
Dim bDone As Boolean
Dim objMMMD As Word.Document
Dim strColumnName As String
Dim lngCount As Long
Dim strSheetName As String
Dim strPhoneNumber As String
bDone = False
strPhoneNumber = ""
Do
strPhoneNumber = InputBox("Enter the phone number -" & _
" only use 0-9, '-' and '+'," & _
" or blank to quit", _
"Phone number", strStartLetter)
strPhoneNumber = Replace(UCase(Trim(strPhoneNumber)), " ", "")
If Len(strPhoneNumber) = 0 Then
bDone = True
Else
If invalidPhoneNumber(strPhoneNumber) Then
MsgBox "Don't put anything except 0-9," & _
"'-' and '+' in the phone number", _
vbOKOnly
Else
' Set this to the name of the worksheet or to the range name
strSheetName = "Nominal Roll$"
' Set this to the exact name of the column containing the phone
number
' (upper/lower case is probably significant
strColumnName = "PhoneNumber"
Set objMMMD = ActiveDocument
With objMMMD.MailMerge
' I would like to use count(*) to get the
' record count but cannot make it work
.DataSource.QueryString = _
" SELECT *" & _
" FROM [" & strSheetName & "]" & _
" WHERE " & CStr(strColumnName) & " like '" & _
strPhoneNumber & "%'"
.DataSource.ActiveRecord = wdLastRecord
lngCount = .DataSource.ActiveRecord
End With
Set objMMMD = Nothing
Select Case lngCount
Case 0
MsgBox "No records matched the number you entered", vbOKOnly
Case 1 ' OK
bDone = True
Case Else
MsgBox "More than 1 record matched the number you entered",
vbOKOnly
End Select
End If
End If
Loop Until bDone

If strPhoneNumber "" Then
Set objMMMD = ActiveDocument
With objMMMD.MailMerge
' remove or change this as necessary
.Destination = wdSendToNewDocument
.Execute Pause:=False
End With
Set objMMMD = Nothing
End If

End Sub

Function invalidPhoneNumber(ByRef strPhone As String) As Boolean
' Shouldn't really return a parameter
' using byref in a function but
' there you go
Dim c As Long
Dim s As String
s = ""
invalidPhoneNumber = False
For c = 1 To Len(strPhone)
Select Case Mid(strPhone, c, 1)
Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "-"
s = s & Mid(strPhone, c, 1)
Case Else
invalidPhoneNumber = True
End Select
Next
strPhone = s
End Function




Peter Jamieson

http://tips.pjmsn.me.uk
Visit Londinium at http://www.ralphwatson.tv

Michael Koerner wrote:
Peter;

The phone number is only in one data source which is in this case is Excel
Col " O" with a header row called PhoneNumber and appear as xxx-xxx-xxxx

  #7   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Michael Koerner Michael Koerner is offline
external usenet poster
 
Posts: 41
Default Selecting Only One Record In A Merge

Peter;

After correcting a couple word wraps from the cut and paste, I'm on bended
knees to you. Thank you very much, it works like a charm. Now all I need is
someone to help me get up off my knees. g

--

Regards
Michael Koerner


"Peter Jamieson" wrote in message
...
See how you get on with this (it's a completely separate process from
the last one)

FWIW I try to keep the amount of "coding to order" I do to an absolute
minimum. This is more than I've done for some time.

Sub SelectPhoneNumberAndMerge()
' error trapping to be added
Dim bDone As Boolean
Dim objMMMD As Word.Document
Dim strColumnName As String
Dim lngCount As Long
Dim strSheetName As String
Dim strPhoneNumber As String
bDone = False
strPhoneNumber = ""
Do
strPhoneNumber = InputBox("Enter the phone number -" & _
" only use 0-9, '-' and '+'," & _
" or blank to quit", _
"Phone number", strStartLetter)
strPhoneNumber = Replace(UCase(Trim(strPhoneNumber)), " ", "")
If Len(strPhoneNumber) = 0 Then
bDone = True
Else
If invalidPhoneNumber(strPhoneNumber) Then
MsgBox "Don't put anything except 0-9," & _
"'-' and '+' in the phone number", _
vbOKOnly
Else
' Set this to the name of the worksheet or to the range name
strSheetName = "Nominal Roll$"
' Set this to the exact name of the column containing the phone
number
' (upper/lower case is probably significant
strColumnName = "PhoneNumber"
Set objMMMD = ActiveDocument
With objMMMD.MailMerge
' I would like to use count(*) to get the
' record count but cannot make it work
.DataSource.QueryString = _
" SELECT *" & _
" FROM [" & strSheetName & "]" & _
" WHERE " & CStr(strColumnName) & " like '" & _
strPhoneNumber & "%'"
.DataSource.ActiveRecord = wdLastRecord
lngCount = .DataSource.ActiveRecord
End With
Set objMMMD = Nothing
Select Case lngCount
Case 0
MsgBox "No records matched the number you entered", vbOKOnly
Case 1 ' OK
bDone = True
Case Else
MsgBox "More than 1 record matched the number you entered",
vbOKOnly
End Select
End If
End If
Loop Until bDone

If strPhoneNumber "" Then
Set objMMMD = ActiveDocument
With objMMMD.MailMerge
' remove or change this as necessary
.Destination = wdSendToNewDocument
.Execute Pause:=False
End With
Set objMMMD = Nothing
End If

End Sub

Function invalidPhoneNumber(ByRef strPhone As String) As Boolean
' Shouldn't really return a parameter
' using byref in a function but
' there you go
Dim c As Long
Dim s As String
s = ""
invalidPhoneNumber = False
For c = 1 To Len(strPhone)
Select Case Mid(strPhone, c, 1)
Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "-"
s = s & Mid(strPhone, c, 1)
Case Else
invalidPhoneNumber = True
End Select
Next
strPhone = s
End Function




Peter Jamieson

http://tips.pjmsn.me.uk
Visit Londinium at http://www.ralphwatson.tv

Michael Koerner wrote:
Peter;

The phone number is only in one data source which is in this case is Excel
Col " O" with a header row called PhoneNumber and appear as xxx-xxx-xxxx



  #8   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Selecting Only One Record In A Merge

It's OK Michael, you can get up now :-))

Seriously, glad it works.

Peter Jamieson

http://tips.pjmsn.me.uk
Visit Londinium at http://www.ralphwatson.tv

Michael Koerner wrote:
Peter;

After correcting a couple word wraps from the cut and paste, I'm on bended
knees to you. Thank you very much, it works like a charm. Now all I need is
someone to help me get up off my knees. g

  #9   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Michael Koerner Michael Koerner is offline
external usenet poster
 
Posts: 41
Default Selecting Only One Record In A Merge

Peter I was a little quick to answer. I ran it again, and received the
following VB Compile Error "Ambiguous name detected: invalidPhoneNumber" and
the following opens up as highlighted

Function invalidPhoneNumber(ByRef strPhone As String) As Boolean

--

Regards
Michael Koerner


"Peter Jamieson" wrote in message
...
See how you get on with this (it's a completely separate process from
the last one)

FWIW I try to keep the amount of "coding to order" I do to an absolute
minimum. This is more than I've done for some time.

Sub SelectPhoneNumberAndMerge()
' error trapping to be added
Dim bDone As Boolean
Dim objMMMD As Word.Document
Dim strColumnName As String
Dim lngCount As Long
Dim strSheetName As String
Dim strPhoneNumber As String
bDone = False
strPhoneNumber = ""
Do
strPhoneNumber = InputBox("Enter the phone number -" & _
" only use 0-9, '-' and '+'," & _
" or blank to quit", _
"Phone number", strStartLetter)
strPhoneNumber = Replace(UCase(Trim(strPhoneNumber)), " ", "")
If Len(strPhoneNumber) = 0 Then
bDone = True
Else
If invalidPhoneNumber(strPhoneNumber) Then
MsgBox "Don't put anything except 0-9," & _
"'-' and '+' in the phone number", _
vbOKOnly
Else
' Set this to the name of the worksheet or to the range name
strSheetName = "Nominal Roll$"
' Set this to the exact name of the column containing the phone
number
' (upper/lower case is probably significant
strColumnName = "PhoneNumber"
Set objMMMD = ActiveDocument
With objMMMD.MailMerge
' I would like to use count(*) to get the
' record count but cannot make it work
.DataSource.QueryString = _
" SELECT *" & _
" FROM [" & strSheetName & "]" & _
" WHERE " & CStr(strColumnName) & " like '" & _
strPhoneNumber & "%'"
.DataSource.ActiveRecord = wdLastRecord
lngCount = .DataSource.ActiveRecord
End With
Set objMMMD = Nothing
Select Case lngCount
Case 0
MsgBox "No records matched the number you entered", vbOKOnly
Case 1 ' OK
bDone = True
Case Else
MsgBox "More than 1 record matched the number you entered",
vbOKOnly
End Select
End If
End If
Loop Until bDone

If strPhoneNumber "" Then
Set objMMMD = ActiveDocument
With objMMMD.MailMerge
' remove or change this as necessary
.Destination = wdSendToNewDocument
.Execute Pause:=False
End With
Set objMMMD = Nothing
End If

End Sub

Function invalidPhoneNumber(ByRef strPhone As String) As Boolean
' Shouldn't really return a parameter
' using byref in a function but
' there you go
Dim c As Long
Dim s As String
s = ""
invalidPhoneNumber = False
For c = 1 To Len(strPhone)
Select Case Mid(strPhone, c, 1)
Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "-"
s = s & Mid(strPhone, c, 1)
Case Else
invalidPhoneNumber = True
End Select
Next
strPhone = s
End Function




Peter Jamieson

http://tips.pjmsn.me.uk
Visit Londinium at http://www.ralphwatson.tv

Michael Koerner wrote:
Peter;

The phone number is only in one data source which is in this case is Excel
Col " O" with a header row called PhoneNumber and appear as xxx-xxx-xxxx



  #10   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Selecting Only One Record In A Merge

I suspected it was too good to be true!

I don't suppose you have copied/pasted the macro into more than one
place, e.g. into a macro in the document, and a macro in the normal
template or an attached template?

FWIW, when faced with this kind of stuff I tend to
a. ensure that the active document is the one I intended it to be.
After you've run it once, the active document is often something else,
e.g. the output document from the previous merge. (probably wouldn't
cause this particular error though)
b. close Word, preferably make sure it's dead, start Word again, open
your mail merge main document, try again.


Peter Jamieson


http://tips.pjmsn.me.uk
Visit Londinium at http://www.ralphwatson.tv

Michael Koerner wrote:
Peter I was a little quick to answer. I ran it again, and received the
following VB Compile Error "Ambiguous name detected: invalidPhoneNumber" and
the following opens up as highlighted

Function invalidPhoneNumber(ByRef strPhone As String) As Boolean



  #11   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Michael Koerner Michael Koerner is offline
external usenet poster
 
Posts: 41
Default Selecting Only One Record In A Merge

I looked, and it saved it as a docm file instead of a dotx. It works only I
get a macro alert message at the beginning where I have to allow the macro
to run.

--

Regards
Michael Koerner


"Peter Jamieson" wrote in message
...
I suspected it was too good to be true!

I don't suppose you have copied/pasted the macro into more than one
place, e.g. into a macro in the document, and a macro in the normal
template or an attached template?

FWIW, when faced with this kind of stuff I tend to
a. ensure that the active document is the one I intended it to be.
After you've run it once, the active document is often something else,
e.g. the output document from the previous merge. (probably wouldn't
cause this particular error though)
b. close Word, preferably make sure it's dead, start Word again, open
your mail merge main document, try again.


Peter Jamieson


http://tips.pjmsn.me.uk
Visit Londinium at http://www.ralphwatson.tv

Michael Koerner wrote:
Peter I was a little quick to answer. I ran it again, and received the
following VB Compile Error "Ambiguous name detected: invalidPhoneNumber"
and
the following opens up as highlighted

Function invalidPhoneNumber(ByRef strPhone As String) As Boolean



  #12   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Selecting Only One Record In A Merge

You may be able to get rid of those by modifying the settings in Word
Office Button-Word OptionsTrust Center-Trust Center Settings, then
-Macro Settings and/or Trusted Locations.


Peter Jamieson

http://tips.pjmsn.me.uk
Visit Londinium at http://www.ralphwatson.tv

Michael Koerner wrote:
I looked, and it saved it as a docm file instead of a dotx. It works only I
get a macro alert message at the beginning where I have to allow the macro
to run.

  #13   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Michael Koerner Michael Koerner is offline
external usenet poster
 
Posts: 41
Default Selecting Only One Record In A Merge

Understood, as long as I allow all macros. Thanks

--

Regards
Michael Koerner


"Peter Jamieson" wrote in message
...
You may be able to get rid of those by modifying the settings in Word
Office Button-Word OptionsTrust Center-Trust Center Settings, then
-Macro Settings and/or Trusted Locations.


Peter Jamieson

http://tips.pjmsn.me.uk
Visit Londinium at http://www.ralphwatson.tv

Michael Koerner wrote:
I looked, and it saved it as a docm file instead of a dotx. It works only
I
get a macro alert message at the beginning where I have to allow the macro
to run.



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting Multiple Recipients for merge bigjimdogg Mailmerge 2 February 3rd 07 07:44 AM
selecting records to merge Sandi B Mailmerge 1 November 14th 06 05:09 AM
sort mail merge by merge record number nathan Mailmerge 1 August 10th 05 07:09 AM
Merge files keep selecting their own fields. How to fix? Jennifer C. South Bend Mailmerge 2 June 16th 05 09:42 PM
label merge only 1st record is merging-rest of source won't merge harriet Mailmerge 2 March 29th 05 04:26 PM


All times are GMT +1. The time now is 08:35 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"