Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2007

Tip: Looking for answers? Try searching our database.

Run Time error on Code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Angyl - 21 Nov 2007 22:01 GMT
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.

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.