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

Re: Run Time error on Code by Russ

Russ
Wed Nov 21 14:45:35 PST 2007

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.
>
> 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

drsmN0SPAMikleAThotmailD0Tcom.INVALID


Re: Run Time error on Code by fumei

fumei
Thu Nov 29 13:32:13 PST 2007

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

Angyl wrote:
>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

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/200711/1


Re: Run Time error on Code by David

David
Fri Nov 30 10:21:47 PST 2007

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.