View Single Post
  #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,



-