A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook - Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Customising an error message



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old October 20th 06, 02:21 AM posted to microsoft.public.outlook.program_forms
[email protected]
external usenet poster
 
Posts: 6
Default Customising an error message

Hello,

I'm using the following code to open a word document saved on a network
drive

Sub label105_click
Set Word = CreateObject("Word.Application")
Word.Visible = TRUE
Word.Documents.open("G:\whatever.dot")
End Sub

I've been assured that almost everyone in the company has access to the
G:\ - however I'd like to make a message box appear if Word can't
access the document - something like "Please contact IT to map your
G:\"

Can I just alter the code so it states....

Sub label105_click
Set Word = CreateObject("Word.Application")
Word.Visible = TRUE
Word.Documents.open("G:\whatever.dot")
If Word.Documents.open Is Nothing Then
MsgBox "Please contact IT to map your G:\"
Else
End Sub

Ads
  #2  
Old October 20th 06, 02:55 AM posted to microsoft.public.outlook.program_forms
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Customising an error message

That's close, but you need to explicitly return the Document object from the Open method:

On Error Resume Next
Set doc = Word.Documents.open("G:\whatever.dot")
If doc Is Nothing Then
MsgBox "Please contact IT to map your G:\"
Else
' do stuff with doc
End If


--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

wrote in message oups.com...
Hello,

I'm using the following code to open a word document saved on a network
drive

Sub label105_click
Set Word = CreateObject("Word.Application")
Word.Visible = TRUE
Word.Documents.open("G:\whatever.dot")
End Sub

I've been assured that almost everyone in the company has access to the
G:\ - however I'd like to make a message box appear if Word can't
access the document - something like "Please contact IT to map your
G:\"

Can I just alter the code so it states....

Sub label105_click
Set Word = CreateObject("Word.Application")
Word.Visible = TRUE
Word.Documents.open("G:\whatever.dot")
If Word.Documents.open Is Nothing Then
MsgBox "Please contact IT to map your G:\"
Else
End Sub

  #3  
Old October 20th 06, 04:42 AM posted to microsoft.public.outlook.program_forms
Hollis Paul
external usenet poster
 
Posts: 242
Default Customising an error message

In article .com,
wrote:
Sub label105_click
Set Word = CreateObject("Word.Application")
Word.Visible = TRUE
Word.Documents.open("G:\whatever.dot")
If Word.Documents.open Is Nothing Then
MsgBox "Please contact IT to map your G:\"
Else
End Sub

If I read the code naively, then the last open on "Word.Documents.open"
is a method, not an object. So, this line should throw an error to the
effect that no document is found. And really, you have created a world
of confusion for yourself by naming your Word Application Object
"Word". You should be using naming practices to make clear what the
objects are in lines of code removed from where you create them.

So, you should use something line the following for the first object:

Set myWordApp = CreateObject("Word.Application")

and you should test that object to see if you created it.

Then, if Word were structured like Outlook, and it really isn't, you
would have to create a Documents collection object. But, in looking
quickly through my last custom form using Word Documents, I find where
the document object is created, and the next thing I see is where a
template is added:

myWordApp.Documents.Add strWordTemplate
myWordApp.Visible = True
myWordDoc = myWordApp.ActiveDocument

In any case, I think you need to find an example of working with Word
documents through Outlook, set up a VBA project, set references to the
several Word object models, and get creative with the Object Browser
(F2) to find the names of the objects you need to use, and the name of
the methods you will have to use, and find out what each does.

This is no easy task for a hard day's night's burning of the midnight
oil. It will probably take several weeks. Be sure and tell your
supervisor so time will be allocated for the task.

I think you can find a relevant code example on www.outlookcode.com .
I found my starter example on an old, old web-site, and I would not
recommend anyone else go that route.

--
Hollis Paul
Mukilteo, WA USA


  #4  
Old October 20th 06, 06:17 AM posted to microsoft.public.outlook.program_forms
[email protected]
external usenet poster
 
Posts: 6
Default Customising an error message

Thanks for your reply Hollis. I'm a bit of a newbie when it comes to VB
code. As I'm successfully using the basic code without the error
message box, I thought it would be an easy case of adding something
like "if there's an error in opening the document, then display this
message" however it all looks a bit more complicated than I imagined.

If there isn't a simple 'if error, then msgbox' code fix then I think
I'll leave the code alone.

Thanks again.

  #5  
Old October 23rd 06, 12:09 AM posted to microsoft.public.outlook.program_forms
[email protected]
external usenet poster
 
Posts: 6
Default Customising an error message

Thanks Sue,

I'm now using the following code:

Sub label105_click
Set Word = CreateObject("Word.Application")
Word.Visible = TRUE
Word.Documents.open("G:\whatever.dot")
On Error Resume Next
Set doc = Word.Documents.open("G:\whatever.dot")
If doc Is Nothing Then
MsgBox "Please contact IT to map your G:\"
Else
End If

I trust that it will work (My testing is limited as I can't upload the
form to the public drive - and our IT department get a bit narky with
me when I keep asking them to re-upload the form).

  #6  
Old October 23rd 06, 01:06 AM posted to microsoft.public.outlook.program_forms
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Customising an error message

You'll want to put that On Error Resume Next as the first line in the Sub.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

wrote in message oups.com...
Thanks Sue,

I'm now using the following code:

Sub label105_click
Set Word = CreateObject("Word.Application")
Word.Visible = TRUE
Word.Documents.open("G:\whatever.dot")
On Error Resume Next
Set doc = Word.Documents.open("G:\whatever.dot")
If doc Is Nothing Then
MsgBox "Please contact IT to map your G:\"
Else
End If

I trust that it will work (My testing is limited as I can't upload the
form to the public drive - and our IT department get a bit narky with
me when I keep asking them to re-upload the form).

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
customising calendar print view... Ian R Outlook - Calandaring 0 May 18th 06 12:48 PM
Problem customising display of Outlook 2003 Calendar SHPA7 Outlook - Calandaring 1 February 12th 06 09:45 PM
Customising a contacts form Kim Outlook - Using Contacts 1 February 2nd 06 03:35 PM
Customising Forms [email protected] Outlook - Using Forms 1 January 31st 06 01:04 PM
Customising the (GAL) Outlook addressbook C.Davis Outlook - Using Contacts 1 January 18th 06 05:00 PM


All times are GMT +1. The time now is 02:19 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2024 Outlook Banter.
The comments are property of their posters.