I'm using a bit of code to save a document as and automatically populating
the file name with form field data.
Seems to work fine...the Save As Dialog appears, the proper field names are
there for the save as, but then if you click "Save" I get a run error
"Run-time error '-2147(bunch of other numbers)'
Command failed
And that's it. Any idea what I'm supposed to do to fix this? here's the
code I'm using:
response = MsgBox("Form Complete! Do you want to save this survey now?",
vbQuestion + vbYesNo)
If response = vbYes Then
Dim dlg As FileDialog
Set dlg = Application.FileDialog(msoFileDialogSaveAs)
With dlg
.InitialFileName = "c:\Documents and Settings\My Documents\Survey -
" + ActiveDocument.FormFields("textLast").Result + ", " +
ActiveDocument.FormFields("textFirst").Result + ".doc"
If .Show Then .Execute
End With
End If
Russ - 21 Nov 2007 22:45 GMT
I might try inserting this after building the string.
Msgbox "<<" & .InitialFileName & ">>"
To see if what is between the chevrons is a legitimate filename without
rogue characters not allowed in a dos path.
Also I try to use a ampersand &, not plus +, to concatenate strings so I
don't accidentally do math instead.
> I'm using a bit of code to save a document as and automatically populating
> the file name with form field data.
[quoted text clipped - 20 lines]
> End With
> End If

Signature
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID
fumei - 29 Nov 2007 21:32 GMT
I can not duplicate this. i get no errors running:
Dim response
response = MsgBox("Form Complete! Do you want to save this survey now?", _
vbQuestion + vbYesNo)
If response = vbYes Then
Dim dlg As FileDialog
Set dlg = Application.FileDialog(msoFileDialogSaveAs)
With dlg
.InitialFileName = _
"c:\Test\Survey -" _
& ActiveDocument.FormFields("textLast").Result _
& ", " & ActiveDocument.FormFields("textFirst").Result & ".
doc"
If .Show Then .Execute
End With
End If
>I'm using a bit of code to save a document as and automatically populating
>the file name with form field data.
[quoted text clipped - 20 lines]
> End With
> End If
David Sisson - 30 Nov 2007 18:21 GMT
The help file on '.InitialFileName ' also states:
Setting this property to a string longer than 256 characters will
cause a run-time error.
Along with Russ' suggestion, you might try
Msgbox( len (.InitialFileName))
...just in case something screwy is going on.