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 / February 2007

Tip: Looking for answers? Try searching our database.

Msgbox help

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
LEU - 25 Feb 2007 20:52 GMT
In my document form I have a command button that pastes information into my
form. How would I add to my existing macro that if “c:\TempA.doc” does not
exist it would give a message that the file does not exist and then it
returns to the open form. Right now if “c:\TempA.doc” does not exist it gives
an error “5174” and stops the macro.

Private Sub CmdPaste1_Click()
Dim DocA As Document
Dim oFF As FormFields
Set DocA = Documents.Open("c:\TempA.doc")
Set oFF = ActiveDocument.FormFields
Me.Text3.Value = oFF("Text41").Result
Me.Text4.Value = oFF("Text27").Result
Me.Text5.Value = oFF("Text28").Result
‘AND SO ON
DocA.Close
Kill "c:\TempA.doc"
Set DocA = Nothing
Set oFF = Nothing
End Sub
Greg Maxey - 25 Feb 2007 21:15 GMT
Use error handling:

Private Sub CommandButton1_Click()
Dim DocA As Document
Dim oFF As FormFields
On Error GoTo Err_Handler
Set DocA = Documents.Open("c:\TempA.doc")
Set oFF = ActiveDocument.FormFields
'Me.Text3.Value = oFF("Text41").Result
'Me.Text4.Value = oFF("Text27").Result
'Me.Text5.Value = oFF("Text28").Result
DocA.Close
Kill "c:\TempA.doc"
Set DocA = Nothing
Set oFF = Nothing
Exit Sub
Err_Handler:
If Err.Number = 5174 Then MsgBox "File does not exists"
End Sub

See:
http://gregmaxey.mvps.org/Error_Handling_Basics.htm

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> In my document form I have a command button that pastes information
> into my form. How would I add to my existing macro that if
[quoted text clipped - 17 lines]
> Set oFF = Nothing
> End Sub
LEU - 25 Feb 2007 22:14 GMT
Greg,

When I run it, it gives me a compile error 'Label not Defined'
It stops at the following line in the macro:

On Error GoTo Err_Handler

LEU

> Use error handling:
>
[quoted text clipped - 40 lines]
> > Set oFF = Nothing
> > End Sub
Greg Maxey - 25 Feb 2007 22:38 GMT
That is what you will see if you don't have

Err_Handler:

after the Exit Sub line in the code I posted.  Are you sure you applied
"all" of the code I provided to you?

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Greg,
>
[quoted text clipped - 55 lines]
>>> Set oFF = Nothing
>>> End Sub
LEU - 25 Feb 2007 22:45 GMT
I found my problem.  Fat fingers when typing. It works fine just the way you
had it. Thanks for the fast responce.
LEU

> That is what you will see if you don't have
>
[quoted text clipped - 62 lines]
> >>> Set oFF = Nothing
> >>> End Sub
 
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.