Reply
 
Thread Tools Display Modes
  #1   Report Post  
rutica rutica is offline
Junior Member
 
Posts: 14
Default make buttons invisible

I have a Microsoft Word 2003 document that has mail merge fields with Excel as its data source.

I created a few command buttons on my main form. One button allows the user to select the data source, one allows the user to select recipients and the third Merges the data and creates a new document.

I would like those command buttons to *not* appear on the newly created documents.

Here is my code for the button that creates the new document:

Private Sub cmdMergeDocument_Click()
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True

Me.cmdSelectDataSource.Visible = False 'this doesn't work!
Me.cmdMergeDocument.Visible = False 'this doesn't work!
Me.cmdSelectRecipients.Visible = False 'this doesn't work!

With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With

'now show the buttons again on the main form
Me.cmdSelectDataSource.Visible = True 'this doesn't work!
Me.cmdMergeDocument.Visible = True 'this doesn't work!
Me.cmdSelectRecipients.Visible = True 'this doesn't work!
End Sub

I get 'Object doesn't support this property or method'.

I am able to do: cmdSelectDataSource.Enabled = False, but it's not what I need. I need the buttons invisible, not disabled.

Help!
Thanks,
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default make buttons invisible

See my response to your post of yesterday, or save the document as a
template to which you add a custom toolbar containing buttons to run your
code. ActiveX buttons are not suitable for use in a document that is to be
printed.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"rutica" wrote in message
...

I have a Microsoft Word 2003 document that has mail merge fields with
Excel as its data source.

I created a few command buttons on my main form. One button allows the
user to select the data source, one allows the user to select
recipients and the third Merges the data and creates a new document.

I would like those command buttons to *not* appear on the newly created
documents.

Here is my code for the button that creates the new document:

Private Sub cmdMergeDocument_Click()
With ActiveDocument.MailMerge
Destination = wdSendToNewDocument
SuppressBlankLines = True

Me.cmdSelectDataSource.Visible = False 'this doesn't work!
Me.cmdMergeDocument.Visible = False 'this doesn't work!
Me.cmdSelectRecipients.Visible = False 'this doesn't work!

With .DataSource
FirstRecord = wdDefaultFirstRecord
LastRecord = wdDefaultLastRecord
End With
Execute Pause:=False
End With

'now show the buttons again on the main form
Me.cmdSelectDataSource.Visible = True 'this doesn't work!
Me.cmdMergeDocument.Visible = True 'this doesn't work!
Me.cmdSelectRecipients.Visible = True 'this doesn't work!
End Sub

I get 'Object doesn't support this property or method'.

I am able to do: cmdSelectDataSource.Enabled = False, but it's not what
I need. I need the buttons invisible, not disabled.

Help!
Thanks,




--
rutica


  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default make buttons invisible

Perhaps the best you can do is save their .Length and .Width properties,
set them each to 1 prior to the merge, then set them back to the saved
values.

Unless there is another approach that would fit your application, e.g.
you insert macrobutton fields and connect them to appropriate VBA
functions, then remove the buttons altogether prior to merging, then
re-insert them after.

Peter Jamieson

http://tips.pjmsn.me.uk

rutica wrote:
I have a Microsoft Word 2003 document that has mail merge fields with
Excel as its data source.

I created a few command buttons on my main form. One button allows the
user to select the data source, one allows the user to select
recipients and the third Merges the data and creates a new document.

I would like those command buttons to *not* appear on the newly created
documents.

Here is my code for the button that creates the new document:

Private Sub cmdMergeDocument_Click()
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True

Me.cmdSelectDataSource.Visible = False 'this doesn't work!
Me.cmdMergeDocument.Visible = False 'this doesn't work!
Me.cmdSelectRecipients.Visible = False 'this doesn't work!

With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With

'now show the buttons again on the main form
Me.cmdSelectDataSource.Visible = True 'this doesn't work!
Me.cmdMergeDocument.Visible = True 'this doesn't work!
Me.cmdSelectRecipients.Visible = True 'this doesn't work!
End Sub

I get 'Object doesn't support this property or method'.

I am able to do: cmdSelectDataSource.Enabled = False, but it's not what
I need. I need the buttons invisible, not disabled.

Help!
Thanks,




  #4   Report Post  
rutica rutica is offline
Junior Member
 
Posts: 14
Default

thanks for writing.

Peter, I tried Me.cmdMergeDocument.Width = 1 and it works!

The only weird thing is setting it back to normal on the main document. I want my height=45 and my width=117.

But for some reason, if my code lists the height first:
Me.cmdSelectDataSource.height =45
Me.cmdSelectDataSource.width=117
then both the height and the width are 117.

If i list the width first:
Me.cmdSelectDataSource.width=117
Me.cmdSelectDataSource.height=45
then both the height and the width are 45.

It's seems to only consider the last command and then apply that value to both height and width?

Here is my code that shows both the height and width as 45:

With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource

'make the buttons small
Me.cmdMergeDocument.Width = 1
Me.cmdSelectDataSource.Width = 1
Me.cmdSelectRecipients.Width = 1

.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord

End With
.Execute Pause:=False
End With

'now re-size the buttons again
Me.cmdSelectDataSource.Width = 117
Me.cmdSelectDataSource.Height = 45

Me.cmdSelectRecipients.Width = 117
Me.cmdSelectRecipients.Height = 45

Me.cmdMergeDocument.Width = 117
Me.cmdMergeDocument.Height = 45

How can i make the width=117 and the height=45?

Weird.

Quote:
Originally Posted by Peter Jamieson View Post
Perhaps the best you can do is save their .Length and .Width properties,
set them each to 1 prior to the merge, then set them back to the saved
values.

Unless there is another approach that would fit your application, e.g.
you insert macrobutton fields and connect them to appropriate VBA
functions, then remove the buttons altogether prior to merging, then
re-insert them after.

Peter Jamieson

http://tips.pjmsn.me.uk

rutica wrote:
I have a Microsoft Word 2003 document that has mail merge fields with
Excel as its data source.

I created a few command buttons on my main form. One button allows the
user to select the data source, one allows the user to select
recipients and the third Merges the data and creates a new document.

I would like those command buttons to *not* appear on the newly created
documents.

Here is my code for the button that creates the new document:

Private Sub cmdMergeDocument_Click()
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True

Me.cmdSelectDataSource.Visible = False 'this doesn't work!
Me.cmdMergeDocument.Visible = False 'this doesn't work!
Me.cmdSelectRecipients.Visible = False 'this doesn't work!

With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With

'now show the buttons again on the main form
Me.cmdSelectDataSource.Visible = True 'this doesn't work!
Me.cmdMergeDocument.Visible = True 'this doesn't work!
Me.cmdSelectRecipients.Visible = True 'this doesn't work!
End Sub

I get 'Object doesn't support this property or method'.

I am able to do: cmdSelectDataSource.Enabled = False, but it's not what
I need. I need the buttons invisible, not disabled.

Help!
Thanks,



  #5   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default make buttons invisible

I tried something more like


Dim intHeight As Integer
Dim intWidth As Integer

' save the button dimensions

intHeight = Me.cmdSelectDataSource.Height
intWidth = Me.cmdSelectDataSource.Width

' do the merge
'

' restore the button dimensions

Me.cmdSelectDataSource.Height = intHeight
Me.cmdSelectDataSource.Width = intWidth


It seems logically pretty much the same as yours, so
a. it is possible that mine wasn't working quite as I imagined. I'll
have anther look.
b. let's make sure we are using the same kind of buttons. Are you
using the standard "ActiveX" buttons (I think they are "Forms.2"
buttons)? I was actually testing with Word 2007 but I'll have a look
with Word 2003.

Peter Jamieson

http://tips.pjmsn.me.uk

rutica wrote:
thanks for writing.

Peter, I tried Me.cmdMergeDocument.Width = 1 and it works!

The only weird thing is setting it back to normal on the main document.
I want my height=45 and my width=117.

But for some reason, if my code lists the height first:
Me.cmdSelectDataSource.height =45
Me.cmdSelectDataSource.width=117
then both the height and the width are 117.

If i list the width first:
Me.cmdSelectDataSource.width=117
Me.cmdSelectDataSource.height=45
then both the height and the width are 45.

It's seems to only consider the last command and then apply that value
to both height and width?

Here is my code that shows both the height and width as 45:

With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource

'make the buttons small
Me.cmdMergeDocument.Width = 1
Me.cmdSelectDataSource.Width = 1
Me.cmdSelectRecipients.Width = 1

.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord

End With
.Execute Pause:=False
End With

'now re-size the buttons again
Me.cmdSelectDataSource.Width = 117
Me.cmdSelectDataSource.Height = 45

Me.cmdSelectRecipients.Width = 117
Me.cmdSelectRecipients.Height = 45

Me.cmdMergeDocument.Width = 117
Me.cmdMergeDocument.Height = 45

How can i make the width=117 and the height=45?

Weird.

Peter Jamieson;416392 Wrote:
Perhaps the best you can do is save their .Length and .Width properties,

set them each to 1 prior to the merge, then set them back to the saved

values.

Unless there is another approach that would fit your application, e.g.

you insert macrobutton fields and connect them to appropriate VBA
functions, then remove the buttons altogether prior to merging, then
re-insert them after.

Peter Jamieson

http://tips.pjmsn.me.uk

rutica wrote:-
I have a Microsoft Word 2003 document that has mail merge fields with
Excel as its data source.

I created a few command buttons on my main form. One button allows
the
user to select the data source, one allows the user to select
recipients and the third Merges the data and creates a new document.

I would like those command buttons to *not* appear on the newly
created
documents.

Here is my code for the button that creates the new document:

Private Sub cmdMergeDocument_Click()
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True

Me.cmdSelectDataSource.Visible = False 'this doesn't work!
Me.cmdMergeDocument.Visible = False 'this doesn't work!
Me.cmdSelectRecipients.Visible = False 'this doesn't work!

With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With

'now show the buttons again on the main form
Me.cmdSelectDataSource.Visible = True 'this doesn't work!
Me.cmdMergeDocument.Visible = True 'this doesn't work!
Me.cmdSelectRecipients.Visible = True 'this doesn't work!
End Sub

I get 'Object doesn't support this property or method'.

I am able to do: cmdSelectDataSource.Enabled = False, but it's not
what
I need. I need the buttons invisible, not disabled.

Help!
Thanks,



-







  #6   Report Post  
rutica rutica is offline
Junior Member
 
Posts: 14
Default

Peter, thank for writing again. I tried your way, but still got the same result.

Something is forcing my code to be a square, I can't get the height and width to be different. I am using the 'Control toolbox' to create a command button. (In Office 2003: View, Toolbars, Control Toolbox). I don't know if that is ActiveX...

I was able to get around my problem by having the height and width both 75. That suits my needs, this time at least.

Below is my code (to test, I only tried it with the cmdSelectDataSource button). But the code doesn't work. Again, the height and width for cmdSelectDataSource is the same even though the message box I created for testing below shows a different height and width.

My AutoSize property for the 3 buttons is set to False. Could it somehow to related to that? I tested by changing them to True, but no change.

Private Sub cmdMergeDocument_Click()
On Error GoTo Err_error_Click
'merge document-step 3
Dim intHeight As Integer
Dim intWidth As Integer

intHeight = Me.cmdSelectDataSource.Height
intWidth = Me.cmdSelectDataSource.Width

'display the height and width for testing purposes
MsgBox "height is: " & intHeight & " and width is: " & intWidth

If MsgBox("Are you sure you want to create a new document(s)?", vbOKCancel, "Create documents") = vbCancel Then
Exit Sub
End If

'first check if the document if protected. If so, unprotect it. Opening the document triggers code to protect it (see the Document_Open() event)
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.Unprotect "hi"
End If


With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource

'make the buttons small
Me.cmdMergeDocument.Width = 1
Me.cmdSelectDataSource.Width = 1
Me.cmdSelectRecipients.Width = 1

.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord

End With
.Execute Pause:=False
End With

'now re-size the buttons again
Me.cmdSelectDataSource.Height = intHeight
Me.cmdSelectDataSource.Width = intWidth

Me.cmdSelectRecipients.Height = 45
Me.cmdSelectRecipients.Width = 75

Me.cmdMergeDocument.Height = 45
Me.cmdMergeDocument.Width = 75


'protect document again
ThisDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="hi"

Exit_cmdMergeDocument_Click:
Exit Sub

Err_error_Click:
MsgBox Err.Description
Resume Exit_cmdMergeDocument_Click

End Sub

Thanks,


Quote:
Originally Posted by Peter Jamieson View Post
I tried something more like


Dim intHeight As Integer
Dim intWidth As Integer

' save the button dimensions

intHeight = Me.cmdSelectDataSource.Height
intWidth = Me.cmdSelectDataSource.Width

' do the merge
'

' restore the button dimensions

Me.cmdSelectDataSource.Height = intHeight
Me.cmdSelectDataSource.Width = intWidth


It seems logically pretty much the same as yours, so
a. it is possible that mine wasn't working quite as I imagined. I'll
have anther look.
b. let's make sure we are using the same kind of buttons. Are you
using the standard "ActiveX" buttons (I think they are "Forms.2"
buttons)? I was actually testing with Word 2007 but I'll have a look
with Word 2003.

Peter Jamieson

http://tips.pjmsn.me.uk

rutica wrote:
thanks for writing.

Peter, I tried Me.cmdMergeDocument.Width = 1 and it works!

The only weird thing is setting it back to normal on the main document.
I want my height=45 and my width=117.

But for some reason, if my code lists the height first:
Me.cmdSelectDataSource.height =45
Me.cmdSelectDataSource.width=117
then both the height and the width are 117.

If i list the width first:
Me.cmdSelectDataSource.width=117
Me.cmdSelectDataSource.height=45
then both the height and the width are 45.

It's seems to only consider the last command and then apply that value
to both height and width?

Here is my code that shows both the height and width as 45:

With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource

'make the buttons small
Me.cmdMergeDocument.Width = 1
Me.cmdSelectDataSource.Width = 1
Me.cmdSelectRecipients.Width = 1

.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord

End With
.Execute Pause:=False
End With

'now re-size the buttons again
Me.cmdSelectDataSource.Width = 117
Me.cmdSelectDataSource.Height = 45

Me.cmdSelectRecipients.Width = 117
Me.cmdSelectRecipients.Height = 45

Me.cmdMergeDocument.Width = 117
Me.cmdMergeDocument.Height = 45

How can i make the width=117 and the height=45?

Weird.

Peter Jamieson;416392 Wrote:
Perhaps the best you can do is save their .Length and .Width properties,

set them each to 1 prior to the merge, then set them back to the saved

values.

Unless there is another approach that would fit your application, e.g.

you insert macrobutton fields and connect them to appropriate VBA
functions, then remove the buttons altogether prior to merging, then
re-insert them after.

Peter Jamieson

http://tips.pjmsn.me.uk

rutica wrote:-
I have a Microsoft Word 2003 document that has mail merge fields with
Excel as its data source.

I created a few command buttons on my main form. One button allows
the
user to select the data source, one allows the user to select
recipients and the third Merges the data and creates a new document.

I would like those command buttons to *not* appear on the newly
created
documents.

Here is my code for the button that creates the new document:

Private Sub cmdMergeDocument_Click()
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True

Me.cmdSelectDataSource.Visible = False 'this doesn't work!
Me.cmdMergeDocument.Visible = False 'this doesn't work!
Me.cmdSelectRecipients.Visible = False 'this doesn't work!

With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With

'now show the buttons again on the main form
Me.cmdSelectDataSource.Visible = True 'this doesn't work!
Me.cmdMergeDocument.Visible = True 'this doesn't work!
Me.cmdSelectRecipients.Visible = True 'this doesn't work!
End Sub

I get 'Object doesn't support this property or method'.

I am able to do: cmdSelectDataSource.Enabled = False, but it's not
what
I need. I need the buttons invisible, not disabled.

Help!
Thanks,



-




  #7   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default make buttons invisible

Hi, I tried it again with your code on Word 2003 and it is OK here.

If you open your main document and use Alt-F9 to look at the field codes
for the buttons, do you see

{ CONTROL Forms.CommandButton.1 \s }

or something else?

The few properties I changed experimentally (.Autosize, .Wordwrap) made
no difference. However, my test document is extremely simple (just the
three buttons in a Normal style paragraph, with a merge field to the
right or underneath. Again, simple tests (e.g. putting the buttons in a
table, or assigning an image to the button) made no difference, but I
wonder if there is something about the layout of your document that is
causing the difference?


Peter Jamieson

http://tips.pjmsn.me.uk

rutica wrote:
Peter, thank for writing again. I tried your way, but still got the
same result.

Something is forcing my code to be a square, I can't get the height and
width to be different. I am using the 'Control toolbox' to create a
command button. (In Office 2003: View, Toolbars, Control Toolbox). I
don't know if that is ActiveX...

I was able to get around my problem by having the height and width both
75. That suits my needs, this time at least.

Below is my code (to test, I only tried it with the cmdSelectDataSource
button). But the code doesn't work. Again, the height and width for
cmdSelectDataSource is the same even though the message box I created
for testing below shows a different height and width.

My AutoSize property for the 3 buttons is set to False. Could it
somehow to related to that? I tested by changing them to True, but no
change.

Private Sub cmdMergeDocument_Click()
On Error GoTo Err_error_Click
'merge document-step 3
Dim intHeight As Integer
Dim intWidth As Integer

intHeight = Me.cmdSelectDataSource.Height
intWidth = Me.cmdSelectDataSource.Width

'display the height and width for testing purposes
MsgBox "height is: " & intHeight & " and width is: " & intWidth

If MsgBox("Are you sure you want to create a new document(s)?",
vbOKCancel, "Create documents") = vbCancel Then
Exit Sub
End If

'first check if the document if protected. If so, unprotect it. Opening
the document triggers code to protect it (see the Document_Open()
event)
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.Unprotect "hi"
End If


With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource

'make the buttons small
Me.cmdMergeDocument.Width = 1
Me.cmdSelectDataSource.Width = 1
Me.cmdSelectRecipients.Width = 1

.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord

End With
.Execute Pause:=False
End With

'now re-size the buttons again
Me.cmdSelectDataSource.Height = intHeight
Me.cmdSelectDataSource.Width = intWidth

Me.cmdSelectRecipients.Height = 45
Me.cmdSelectRecipients.Width = 75

Me.cmdMergeDocument.Height = 45
Me.cmdMergeDocument.Width = 75


'protect document again
ThisDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
Password:="hi"

Exit_cmdMergeDocument_Click:
Exit Sub

Err_error_Click:
MsgBox Err.Description
Resume Exit_cmdMergeDocument_Click

End Sub

Thanks,


Peter Jamieson;416640 Wrote:
I tried something more like


Dim intHeight As Integer
Dim intWidth As Integer

' save the button dimensions

intHeight = Me.cmdSelectDataSource.Height
intWidth = Me.cmdSelectDataSource.Width

' do the merge
'

' restore the button dimensions

Me.cmdSelectDataSource.Height = intHeight
Me.cmdSelectDataSource.Width = intWidth--
--

It seems logically pretty much the same as yours, so
a. it is possible that mine wasn't working quite as I imagined. I'll

have anther look.
b. let's make sure we are using the same kind of buttons. Are you
using the standard "ActiveX" buttons (I think they are "Forms.2"
buttons)? I was actually testing with Word 2007 but I'll have a look
with Word 2003.

Peter Jamieson

http://tips.pjmsn.me.uk

rutica wrote:-
thanks for writing.

Peter, I tried Me.cmdMergeDocument.Width = 1 and it works!

The only weird thing is setting it back to normal on the main
document.
I want my height=45 and my width=117.

But for some reason, if my code lists the height first:
Me.cmdSelectDataSource.height =45
Me.cmdSelectDataSource.width=117
then both the height and the width are 117.

If i list the width first:
Me.cmdSelectDataSource.width=117
Me.cmdSelectDataSource.height=45
then both the height and the width are 45.

It's seems to only consider the last command and then apply that
value
to both height and width?

Here is my code that shows both the height and width as 45:

With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource

'make the buttons small
Me.cmdMergeDocument.Width = 1
Me.cmdSelectDataSource.Width = 1
Me.cmdSelectRecipients.Width = 1

.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord

End With
.Execute Pause:=False
End With

'now re-size the buttons again
Me.cmdSelectDataSource.Width = 117
Me.cmdSelectDataSource.Height = 45

Me.cmdSelectRecipients.Width = 117
Me.cmdSelectRecipients.Height = 45

Me.cmdMergeDocument.Width = 117
Me.cmdMergeDocument.Height = 45

How can i make the width=117 and the height=45?

Weird.

Peter Jamieson;416392 Wrote: -
Perhaps the best you can do is save their .Length and .Width
properties,

set them each to 1 prior to the merge, then set them back to the
saved

values.

Unless there is another approach that would fit your application,
e.g.

you insert macrobutton fields and connect them to appropriate VBA
functions, then remove the buttons altogether prior to merging, then
re-insert them after.

Peter Jamieson

http://tips.pjmsn.me.uk

rutica wrote:-
I have a Microsoft Word 2003 document that has mail merge fields with
Excel as its data source.

I created a few command buttons on my main form. One button allows
the
user to select the data source, one allows the user to select
recipients and the third Merges the data and creates a new document.

I would like those command buttons to *not* appear on the newly
created
documents.

Here is my code for the button that creates the new document:

Private Sub cmdMergeDocument_Click()
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True

Me.cmdSelectDataSource.Visible = False 'this doesn't work!
Me.cmdMergeDocument.Visible = False 'this doesn't work!
Me.cmdSelectRecipients.Visible = False 'this doesn't work!

With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With

'now show the buttons again on the main form
Me.cmdSelectDataSource.Visible = True 'this doesn't work!
Me.cmdMergeDocument.Visible = True 'this doesn't work!
Me.cmdSelectRecipients.Visible = True 'this doesn't work!
End Sub

I get 'Object doesn't support this property or method'.

I am able to do: cmdSelectDataSource.Enabled = False, but it's not
what
I need. I need the buttons invisible, not disabled.

Help!
Thanks,



--



-





  #8   Report Post  
rutica rutica is offline
Junior Member
 
Posts: 14
Default

I figured it out!

I had to uncheck 'lock aspect ratio'. I right clicked on my command button and selected 'Format Control'. Then in the Size tab, I had to uncheck 'lock aspect ratio'.

Thanks for writing back and trying to help!






Quote:
Originally Posted by Peter Jamieson View Post
Hi, I tried it again with your code on Word 2003 and it is OK here.

If you open your main document and use Alt-F9 to look at the field codes
for the buttons, do you see

{ CONTROL Forms.CommandButton.1 \s }

or something else?

The few properties I changed experimentally (.Autosize, .Wordwrap) made
no difference. However, my test document is extremely simple (just the
three buttons in a Normal style paragraph, with a merge field to the
right or underneath. Again, simple tests (e.g. putting the buttons in a
table, or assigning an image to the button) made no difference, but I
wonder if there is something about the layout of your document that is
causing the difference?


Peter Jamieson

http://tips.pjmsn.me.uk

rutica wrote:
Peter, thank for writing again. I tried your way, but still got the
same result.

Something is forcing my code to be a square, I can't get the height and
width to be different. I am using the 'Control toolbox' to create a
command button. (In Office 2003: View, Toolbars, Control Toolbox). I
don't know if that is ActiveX...

I was able to get around my problem by having the height and width both
75. That suits my needs, this time at least.

Below is my code (to test, I only tried it with the cmdSelectDataSource
button). But the code doesn't work. Again, the height and width for
cmdSelectDataSource is the same even though the message box I created
for testing below shows a different height and width.

My AutoSize property for the 3 buttons is set to False. Could it
somehow to related to that? I tested by changing them to True, but no
change.

Private Sub cmdMergeDocument_Click()
On Error GoTo Err_error_Click
'merge document-step 3
Dim intHeight As Integer
Dim intWidth As Integer

intHeight = Me.cmdSelectDataSource.Height
intWidth = Me.cmdSelectDataSource.Width

'display the height and width for testing purposes
MsgBox "height is: " & intHeight & " and width is: " & intWidth

If MsgBox("Are you sure you want to create a new document(s)?",
vbOKCancel, "Create documents") = vbCancel Then
Exit Sub
End If

'first check if the document if protected. If so, unprotect it. Opening
the document triggers code to protect it (see the Document_Open()
event)
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.Unprotect "hi"
End If


With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource

'make the buttons small
Me.cmdMergeDocument.Width = 1
Me.cmdSelectDataSource.Width = 1
Me.cmdSelectRecipients.Width = 1

.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord

End With
.Execute Pause:=False
End With

'now re-size the buttons again
Me.cmdSelectDataSource.Height = intHeight
Me.cmdSelectDataSource.Width = intWidth

Me.cmdSelectRecipients.Height = 45
Me.cmdSelectRecipients.Width = 75

Me.cmdMergeDocument.Height = 45
Me.cmdMergeDocument.Width = 75


'protect document again
ThisDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
Password:="hi"

Exit_cmdMergeDocument_Click:
Exit Sub

Err_error_Click:
MsgBox Err.Description
Resume Exit_cmdMergeDocument_Click

End Sub

Thanks,


Peter Jamieson;416640 Wrote:
I tried something more like


Dim intHeight As Integer
Dim intWidth As Integer

' save the button dimensions

intHeight = Me.cmdSelectDataSource.Height
intWidth = Me.cmdSelectDataSource.Width

' do the merge
'

' restore the button dimensions

Me.cmdSelectDataSource.Height = intHeight
Me.cmdSelectDataSource.Width = intWidth--
--

It seems logically pretty much the same as yours, so
a. it is possible that mine wasn't working quite as I imagined. I'll

have anther look.
b. let's make sure we are using the same kind of buttons. Are you
using the standard "ActiveX" buttons (I think they are "Forms.2"
buttons)? I was actually testing with Word 2007 but I'll have a look
with Word 2003.

Peter Jamieson

http://tips.pjmsn.me.uk

rutica wrote:-
thanks for writing.

Peter, I tried Me.cmdMergeDocument.Width = 1 and it works!

The only weird thing is setting it back to normal on the main
document.
I want my height=45 and my width=117.

But for some reason, if my code lists the height first:
Me.cmdSelectDataSource.height =45
Me.cmdSelectDataSource.width=117
then both the height and the width are 117.

If i list the width first:
Me.cmdSelectDataSource.width=117
Me.cmdSelectDataSource.height=45
then both the height and the width are 45.

It's seems to only consider the last command and then apply that
value
to both height and width?

Here is my code that shows both the height and width as 45:

With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource

'make the buttons small
Me.cmdMergeDocument.Width = 1
Me.cmdSelectDataSource.Width = 1
Me.cmdSelectRecipients.Width = 1

.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord

End With
.Execute Pause:=False
End With

'now re-size the buttons again
Me.cmdSelectDataSource.Width = 117
Me.cmdSelectDataSource.Height = 45

Me.cmdSelectRecipients.Width = 117
Me.cmdSelectRecipients.Height = 45

Me.cmdMergeDocument.Width = 117
Me.cmdMergeDocument.Height = 45

How can i make the width=117 and the height=45?

Weird.

Peter Jamieson;416392 Wrote: -
Perhaps the best you can do is save their .Length and .Width
properties,

set them each to 1 prior to the merge, then set them back to the
saved

values.

Unless there is another approach that would fit your application,
e.g.

you insert macrobutton fields and connect them to appropriate VBA
functions, then remove the buttons altogether prior to merging, then
re-insert them after.

Peter Jamieson

http://tips.pjmsn.me.uk

rutica wrote:-
I have a Microsoft Word 2003 document that has mail merge fields with
Excel as its data source.

I created a few command buttons on my main form. One button allows
the
user to select the data source, one allows the user to select
recipients and the third Merges the data and creates a new document.

I would like those command buttons to *not* appear on the newly
created
documents.

Here is my code for the button that creates the new document:

Private Sub cmdMergeDocument_Click()
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True

Me.cmdSelectDataSource.Visible = False 'this doesn't work!
Me.cmdMergeDocument.Visible = False 'this doesn't work!
Me.cmdSelectRecipients.Visible = False 'this doesn't work!

With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With

'now show the buttons again on the main form
Me.cmdSelectDataSource.Visible = True 'this doesn't work!
Me.cmdMergeDocument.Visible = True 'this doesn't work!
Me.cmdSelectRecipients.Visible = True 'this doesn't work!
End Sub

I get 'Object doesn't support this property or method'.

I am able to do: cmdSelectDataSource.Enabled = False, but it's not
what
I need. I need the buttons invisible, not disabled.

Help!
Thanks,



--



-




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
Make the table gridlines invisible for printing dodger New Users 2 December 17th 08 10:56 PM
Make changes final or invisible to users Rick Microsoft Word Help 2 December 11th 06 08:12 PM
How to make text invisible firmdew Microsoft Word Help 8 May 7th 06 06:41 AM
how do i make an invisible cursor visible cparrott9 Microsoft Word Help 1 August 1st 05 02:54 AM
How to make pdf maker toolbar invisible macho New Users 8 July 17th 05 02:15 PM


All times are GMT +1. The time now is 05:47 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"