Mombu the Microsoft Forum sponsored links

Go Back   Mombu the Microsoft Forum > Microsoft > EXCHANGE SERVER (TECHNET) > Customising an error message
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 27th October 12:58
dozingquinn
External User
 
Posts: 1
Default Customising an error message


Hello,

I'm using the following code to open a word do***ent saved on a network
drive

Sub label105_click
Set Word = CreateObject("Word.Application")
Word.Visible = TRUE
Word.Do***ents.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 do***ent - 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.Do***ents.open("G:\whatever.dot")
If Word.Do***ents.open Is Nothing Then
MsgBox "Please contact IT to map your G:\"
Else
End Sub
  Reply With Quote


  sponsored links


2 27th October 12:59
hollis paul
External User
 
Posts: 1
Default Customising an error message


If I read the code naively, then the last open on "Word.Do***ents.open"
is a method, not an object. So, this line should throw an error to the
effect that no do***ent 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 Do***ents collection object. But, in looking
quickly through my last custom form using Word Do***ents, I find where
the do***ent object is created, and the next thing I see is where a
template is added:

myWordApp.Do***ents.Add strWordTemplate
myWordApp.Visible = True
myWordDoc = myWordApp.ActiveDo***ent

In any case, I think you need to find an example of working with Word
do***ents 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 http://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
  Reply With Quote
3 27th October 12:59
dozingquinn
External User
 
Posts: 1
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 do***ent, 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.
  Reply With Quote
4 27th October 13:01
sue mosher mvp-outlook
External User
 
Posts: 1
Default Customising an error message


That's close, but you need to ********ly return the Do***ent object from the Open method:

On Error Resume Next
Set doc = Word.Do***ents.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
  Reply With Quote
5 27th October 13:07
dozingquinn
External User
 
Posts: 1
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.Do***ents.open("G:\whatever.dot")
On Error Resume Next
Set doc = Word.Do***ents.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).
  Reply With Quote
6 27th October 13:08
sue mosher mvp-outlook
External User
 
Posts: 1
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
  Reply With Quote


  sponsored links


Reply


Thread Tools
Display Modes




Copyright 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666